Skip to content

Commit

Permalink
Merge pull request #230 from pyswmm/handle-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aerispaha authored Nov 27, 2024
2 parents 93148c0 + 5fe9860 commit 6b2df99
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
markers =
uses_geopandas: marks tests that use Geopandas (deselect with '-m "not uses_geopandas"')
serial
2 changes: 1 addition & 1 deletion swmmio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ def patterns(self):
pattern_entry['Type'] = pattern['Type'].iloc[0]
if pattern.shape[0] > 1:
# shift pattern values to the right
pattern.iloc[1::, 1::] = pattern.iloc[1::, 0:-1].values
pattern.iloc[1::, 1::] = pattern.iloc[1::, 0:-1].values.astype(float)
pattern['Factors'] = pattern['Factors'].astype(float)
values = pattern.iloc[:, 1:].values.flatten()
for i in range(len(values)):
Expand Down
4 changes: 2 additions & 2 deletions swmmio/tests/test_dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_links_dataframe_from_rpt(test_model_02):
C2 PUMP 4.33 0 09:59 0.22 NaN NaN
C3 WEIR 7.00 0 10:00 0.33 NaN NaN
'''
lfs_df = pd.read_csv(StringIO(s), index_col=0, delim_whitespace=True, skiprows=[0])
lfs_df = pd.read_csv(StringIO(s), index_col=0, sep=r'\s+', skiprows=[0])
assert(lfs_df.equals(link_flow_summary))


Expand Down Expand Up @@ -257,7 +257,7 @@ def test_polygons(test_model_02):
S4 -154.695 -168.608
S4 -148.499 -126.120
"""
poly1 = pd.read_csv(StringIO(s), index_col=0, delim_whitespace=True, skiprows=[0])
poly1 = pd.read_csv(StringIO(s), index_col=0, sep=r'\s+', skiprows=[0])

assert poly1.equals(test_model_02.inp.polygons)

Expand Down
2 changes: 1 addition & 1 deletion swmmio/utils/dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def dataframe_from_inp(inp_path, section, additional_cols=None, quote_replace='

if headers[sect]['columns'][0] == 'blob':
# return the whole row, without specific col headers
return pd.read_csv(StringIO(s), delim_whitespace=False)
return pd.read_csv(StringIO(s))
else:
try:
df = pd.read_csv(StringIO(s), header=None, sep=r'\s+',
Expand Down
23 changes: 15 additions & 8 deletions swmmio/version_control/inp.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ def build(self, baseline_dir, target_path):
new_section = basedf.drop(remove_ids)

# add elements
new_section = pd.concat([new_section, changes.altered, changes.added])
# get a list of the dataframes that have changes (omit empty ones)
changes_dfs = list(filter(lambda x: not x.empty, [new_section, changes.altered, changes.added]))
if len(changes_dfs) > 0:
# write the section
vc_utils.write_inp_section(f, allheaders, section, pd.concat(changes_dfs))
else:
# section is not well understood or is problematic, just blindly copy
new_section = dataframe_from_bi(basemodel.inp.path, section=section)
new_section[';'] = ';'

# write the section
vc_utils.write_inp_section(f, allheaders, section, new_section)
vc_utils.write_inp_section(f, allheaders, section, new_section)


class INPSectionDiff(object):
Expand Down Expand Up @@ -313,10 +315,15 @@ def create_inp_build_instructions(inpA, inpB, path, filename, comments=''):
if section not in problem_sections:
# calculate the changes in the current section
changes = INPSectionDiff(modela, modelb, section)
data = pd.concat([changes.removed, changes.added, changes.altered], axis=0, sort=False)
# vc_utils.write_excel_inp_section(excelwriter, allsections_a, section, data)
vc_utils.write_inp_section(newf, allsections_a, section, data, pad_top=False,
na_fill='NaN') # na fill fixes SNOWPACK blanks spaces issue

# get a list of the dataframes that have changes
changes_dfs = list(filter(lambda x: not x.empty, [changes.removed, changes.added, changes.altered]))

# if no changes, don't write the section
if len(changes_dfs) > 0:
data = pd.concat(changes_dfs, axis=0, sort=False)
vc_utils.write_inp_section(newf, allsections_a, section, data, pad_top=False,
na_fill='NaN') # na fill fixes SNOWPACK blanks spaces issue

return BuildInstructions(filepath)

Expand Down
2 changes: 1 addition & 1 deletion swmmio/version_control/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def write_inp_section(file_object, allheaders, sectionheader, section_data, pad_
numformatter = {hedr: ' {{:<{}}}'.format(section_data[hedr].apply(str).str.len().max()).format
for hedr in section_data.columns if section_data[hedr].dtype != "O"}
objectformatter.update(numformatter)
add_str = section_data.fillna(na_fill).to_string(
add_str = section_data.infer_objects(copy=False).fillna(na_fill).to_string(
index_names=False,
header=True,
justify='left',
Expand Down

0 comments on commit 6b2df99

Please sign in to comment.