From 3331597ecc1cf916adc990479261b0de2bd8c63d Mon Sep 17 00:00:00 2001 From: jackieff Date: Wed, 5 May 2021 17:49:03 -0400 Subject: [PATCH] Reverting to 31766d6 --- swmmio/utils/dataframes.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/swmmio/utils/dataframes.py b/swmmio/utils/dataframes.py index ae5c512..612f2f9 100644 --- a/swmmio/utils/dataframes.py +++ b/swmmio/utils/dataframes.py @@ -116,27 +116,31 @@ def dataframe_from_inp(inp_path, section, additional_cols=None, quote_replace=' :param quote_replace: :return: """ - from swmmio.defs import INP_OBJECTS + # format the section header for look up in headers OrderedDict sect = remove_braces(section).upper() + # get list of all section headers in inp to use as section ending flags + headers = get_inp_sections_details(inp_path, include_brackets=False) + + if sect not in headers: + warnings.warn(f'{sect} section not found in {inp_path}') + return pd.DataFrame() + # extract the string and read into a dataframe start_string = format_inp_section_header(section) - end_strings = [format_inp_section_header(h) for h in INP_OBJECTS.keys()] + end_strings = [format_inp_section_header(h) for h in headers.keys()] s = extract_section_of_file(inp_path, start_string, end_strings, **kwargs) - if len(s.replace(start_string, "").replace("\n","")) == 0: - warnings.warn(f'{sect} section not found in {inp_path}') - return pd.DataFrame() # replace occurrences of double quotes "" s = s.replace('""', quote_replace) # and get the list of columns to use for parsing this section # add any additional columns needed for special cases (build instructions) additional_cols = [] if additional_cols is None else additional_cols - cols = INP_OBJECTS[sect]['columns'] + additional_cols + cols = headers[sect]['columns'] + additional_cols - if INP_OBJECTS[sect]['columns'][0] == 'blob': + if headers[sect]['columns'][0] == 'blob': # return the whole row, without specific col headers return pd.read_csv(StringIO(s), delim_whitespace=False) else: