Browse Source

parsing an empty folder without data raise a ValueError

xmlparsing
Holger Frey 3 years ago
parent
commit
c7e8c3455a
  1. 14
      sensospot_data/__init__.py
  2. 15
      sensospot_data/parser.py

14
sensospot_data/__init__.py

@ -87,6 +87,14 @@ def _parse_recursive(source, outfile, quiet):
child_outfile = DEFAULT_OUTPUT_FILENAME child_outfile = DEFAULT_OUTPUT_FILENAME
source_path = Path(source) source_path = Path(source)
folders = (i for i in source_path.iterdir() if i.is_dir()) folders = (i for i in source_path.iterdir() if i.is_dir())
collection = (_parse_one_folder(f, child_outfile, quiet) for f in folders) non_hidden = (i for i in folders if not i.name.startswith("."))
collected_data = pandas.concat(collection, ignore_index=True).reset_index() collection = (
_output(collected_data, source_path, outfile) _parse_one_folder(f, child_outfile, quiet) for f in non_hidden
)
try:
collected_data = pandas.concat(
collection, ignore_index=True
).reset_index()
_output(collected_data, source_path, outfile)
except ValueError as e:
print(str(e))

15
sensospot_data/parser.py

@ -140,10 +140,21 @@ def _sanity_check(data_frame):
def parse_folder(folder, quiet=False): def parse_folder(folder, quiet=False):
"""parses all csv files in a folder to one large dataframe""" """parses all csv files in a folder to one large dataframe
Will raise an ValueError, if no sensospot data could be found in
the folder
folder: path of folder containing data files
quiet: skip sanity check, defaults to False
returns: pandas dataframe with parsed data
"""
folder_path = Path(folder) folder_path = Path(folder)
file_list = list_csv_files(folder_path) file_list = list_csv_files(folder_path)
data_frame = parse_multiple_files(file_list) try:
data_frame = parse_multiple_files(file_list)
except ValueError:
raise ValueError(f"No sensospot data found in folder '{folder}'")
data_frame = add_optional_measurement_parameters(data_frame, folder_path) data_frame = add_optional_measurement_parameters(data_frame, folder_path)
if quiet: if quiet:
return data_frame return data_frame

Loading…
Cancel
Save