Fixed bug in getting file extension
This commit is contained in:
parent
3d7f0ca783
commit
73a5c2cecc
|
@ -1,6 +1,8 @@
|
||||||
# Python Imports
|
# Python Imports
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
import polars
|
||||||
|
|
||||||
# Project Imports
|
# Project Imports
|
||||||
from src.utilities.files.simulation_data_types.json_data_simulation_handler import JsonDataSimulationHandler
|
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
|
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,
|
handlers = {'.csv': CsvDataSimulationHandler,
|
||||||
'.json': JsonDataSimulationHandler,
|
'.json': JsonDataSimulationHandler,
|
||||||
'parquet': ParquetDataSimulationHandler
|
'.parquet': ParquetDataSimulationHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SimulationDataParser:
|
class SimulationDataParser:
|
||||||
|
|
||||||
def __init__(self, file_path):
|
def __init__(self):
|
||||||
self._file_path = file_path
|
self._file_path = None
|
||||||
self._file_extension = 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
|
# Check file exists
|
||||||
self._check_file()
|
self._check_file()
|
||||||
# Check extension
|
# Check extension
|
||||||
|
@ -26,10 +29,9 @@ class SimulationDataParser:
|
||||||
# Get correct handler
|
# Get correct handler
|
||||||
handler = self._get_data_handler()
|
handler = self._get_data_handler()
|
||||||
# Load content
|
# Load content
|
||||||
handler.load_data()
|
polars_df = handler.load_data(self._file_path)
|
||||||
# Convert it to dataframe
|
|
||||||
dataframe = handler.convert_into_dataframe()
|
|
||||||
# Return
|
# Return
|
||||||
|
return polars_df
|
||||||
|
|
||||||
def _check_file(self):
|
def _check_file(self):
|
||||||
exists = os.path.exists(self._file_path)
|
exists = os.path.exists(self._file_path)
|
||||||
|
@ -39,7 +41,7 @@ class SimulationDataParser:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def _check_extension(self):
|
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):
|
def _get_data_handler(self):
|
||||||
handler = handlers.get(self._file_extension)
|
handler = handlers.get(self._file_extension)
|
||||||
|
|
Loading…
Reference in New Issue