From 58436ed5c5a54b5fc7e00a0fa251af5e4cbe3b7f Mon Sep 17 00:00:00 2001 From: Adam Erispaha Date: Wed, 27 Nov 2024 14:12:27 -0500 Subject: [PATCH 1/2] handle all future warnings --- swmmio/core.py | 2 +- swmmio/tests/test_dataframes.py | 4 ++-- swmmio/utils/dataframes.py | 2 +- swmmio/version_control/inp.py | 23 +++++++++++++++-------- swmmio/version_control/utils.py | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/swmmio/core.py b/swmmio/core.py index 49a3839..b8c2815 100644 --- a/swmmio/core.py +++ b/swmmio/core.py @@ -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)): diff --git a/swmmio/tests/test_dataframes.py b/swmmio/tests/test_dataframes.py index 42c21b8..3e8fe3f 100644 --- a/swmmio/tests/test_dataframes.py +++ b/swmmio/tests/test_dataframes.py @@ -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)) @@ -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) diff --git a/swmmio/utils/dataframes.py b/swmmio/utils/dataframes.py index b5ad1a3..a77e003 100644 --- a/swmmio/utils/dataframes.py +++ b/swmmio/utils/dataframes.py @@ -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+', diff --git a/swmmio/version_control/inp.py b/swmmio/version_control/inp.py index 2ac58f3..8f95b3b 100644 --- a/swmmio/version_control/inp.py +++ b/swmmio/version_control/inp.py @@ -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): @@ -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) diff --git a/swmmio/version_control/utils.py b/swmmio/version_control/utils.py index 119950d..ea99ab8 100644 --- a/swmmio/version_control/utils.py +++ b/swmmio/version_control/utils.py @@ -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', From 5fe9860706ea229bf33efb609893f6ccde019c78 Mon Sep 17 00:00:00 2001 From: Adam Erispaha Date: Wed, 27 Nov 2024 14:29:26 -0500 Subject: [PATCH 2/2] handle PytestUnknownMarkWarning --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..4567943 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers = + uses_geopandas: marks tests that use Geopandas (deselect with '-m "not uses_geopandas"') + serial