Skip to content

Commit

Permalink
Fix for change with quotechar and delim flex in built in csvwriter (#547
Browse files Browse the repository at this point in the history
)

* Update CI to test py3.13

Expecting fails

* fix for py3.13 csv writer change (quotchar!=delim)

For now writing df rows as space delim strings

* same treatment for hfb tpl write

* tpl no longer written with random extra space
  • Loading branch information
briochh authored Oct 24, 2024
1 parent e610e4a commit 459eda8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest] # , macos-latest]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
run-type: [std]
test-path: ["."]
include:
- os: macos-latest
python-version: 3.9
python-version: 3.11

steps:
- name: Checkout repo
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test Notebooks
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11 }}
shell: bash -l {0}
working-directory: ./examples
run: |
Expand Down
6 changes: 3 additions & 3 deletions autotest/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,9 +1745,9 @@ def hfb_zn_mult_test(tmp_path):
hfb_pars = pd.read_csv(os.path.join(m.model_ws, 'hfb6_pars.csv'))
hfb_tpl_contents = open(tpl_file, 'r').readlines()
mult_str = ''.join(hfb_tpl_contents[1:]).replace(
'~ hbz_0000 ~', '0.1').replace(
'~ hbz_0001 ~', '1.0').replace(
'~ hbz_0002 ~', '10.0')
'~ hbz_0000 ~', '0.1').replace(
'~ hbz_0001 ~', '1.0').replace(
'~ hbz_0002 ~', '10.0')
with open(hfb_pars.mlt_file.values[0], 'w') as mfp:
mfp.write(mult_str)
pyemu.gw_utils.apply_hfb_pars(os.path.join(m.model_ws, 'hfb6_pars.csv'))
Expand Down
6 changes: 2 additions & 4 deletions pyemu/utils/gw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2749,10 +2749,8 @@ def write_hfb_zone_multipliers_template(m):
with open(tpl_file, "w", newline="") as ofp:
ofp.write("ptf ~\n")
[ofp.write("{0}\n".format(line.strip())) for line in header]
ofp.flush()
hfb_in[["lay", "irow1", "icol1", "irow2", "icol2", "tpl"]].to_csv(
ofp, sep=" ", quotechar=" ", header=None, index=None, mode="a"
)
hfb_in[["lay", "irow1", "icol1", "irow2", "icol2", "tpl"]].apply(
lambda x: ofp.write(' '.join(x.astype(str)) + '\n'), axis=1)

# make a lookup for lining up the necessary files to
# perform multiplication with the helpers.apply_hfb_pars() function
Expand Down
4 changes: 2 additions & 2 deletions pyemu/utils/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

ext = ""
bin_path = os.path.join("..", "bin")
if "linux" in platform.platform().lower():
if "linux" in platform.system().lower():
bin_path = os.path.join(bin_path, "linux")
elif "darwin" in platform.platform().lower():
elif "darwin" in platform.system().lower():
bin_path = os.path.join(bin_path, "mac")
else:
bin_path = os.path.join(bin_path, "win")
Expand Down
25 changes: 14 additions & 11 deletions pyemu/utils/pp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

pd.options.display.max_colwidth = 100
from pyemu.pst.pst_utils import SFMT, IFMT, FFMT, pst_config
from pyemu.utils.helpers import run, _write_df_tpl
from ..pyemu_warnings import PyemuWarning

PP_FMT = {
Expand Down Expand Up @@ -616,16 +615,20 @@ def pilot_points_to_tpl(pp_file, tpl_file=None, name_prefix=None):
pp_df.loc[:, "tpl"] = pp_df.parnme.apply(
lambda x: "~ {0} ~".format(x)
)
_write_df_tpl(
tpl_file,
pp_df.loc[:, ["name", "x", "y", "zone", "tpl"]],
sep=" ",
index_label="index",
header=False,
index=False,
quotechar=" ",
quoting=2,
)
with open(tpl_file, "w") as f:
f.write("ptf ~\n")
pp_df.loc[:, ["name", "x", "y", "zone", "tpl"]].apply(
lambda x: f.write(' '.join(x.astype(str)) + '\n'), axis=1)
# _write_df_tpl(
# tpl_file,
# pp_df.loc[:, ["name", "x", "y", "zone", "tpl"]],
# sep=" ",
# index_label="index",
# header=False,
# index=False,
# quotechar=" ",
# quoting=2,
# )

return pp_df

Expand Down

0 comments on commit 459eda8

Please sign in to comment.