Fixed bug in getting file extension

This commit is contained in:
Alberto Soutullo Rendo 2022-11-27 18:58:08 +01:00
parent 3d7f0ca783
commit 73a5c2cecc
1 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,8 @@
# Python Imports
import os.path
import polars
# Project Imports
from src.utilities.files.simulation_data_types.json_data_simulation_handler import JsonDataSimulationHandler
from src.utilities.files.simulation_data_types.csv_data_simulation_handler import CsvDataSimulationHandler
@ -8,17 +10,18 @@ from src.utilities.files.simulation_data_types.parquet_simulation_data_handler i
handlers = {'.csv': CsvDataSimulationHandler,
'.json': JsonDataSimulationHandler,
'parquet': ParquetDataSimulationHandler
'.parquet': ParquetDataSimulationHandler
}
class SimulationDataParser:
def __init__(self, file_path):
self._file_path = file_path
def __init__(self):
self._file_path = None
self._file_extension = None
def read_content(self):
def read_content(self, file_path: str) -> polars.DataFrame:
self._file_path = file_path
# Check file exists
self._check_file()
# Check extension
@ -26,10 +29,9 @@ class SimulationDataParser:
# Get correct handler
handler = self._get_data_handler()
# Load content
handler.load_data()
# Convert it to dataframe
dataframe = handler.convert_into_dataframe()
polars_df = handler.load_data(self._file_path)
# Return
return polars_df
def _check_file(self):
exists = os.path.exists(self._file_path)
@ -39,7 +41,7 @@ class SimulationDataParser:
exit(1)
def _check_extension(self):
return os.path.splitext(self._file_path)[1]
self._file_extension = os.path.splitext(self._file_path)[1]
def _get_data_handler(self):
handler = handlers.get(self._file_extension)