Skip to content

Commit

Permalink
dev: in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mysiar committed Oct 14, 2024
1 parent 6ba14a5 commit bb38493
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
23 changes: 14 additions & 9 deletions data_flow/data_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ def to_hdf(self, filename: str, key: str = "key"):
to_hdf_from_file(filename=filename, tmp_filename=self.__filename, file_type=self.__file_type, key=key)
return self

def del_columns(self, columns: list):
def columns(self) -> list:
if self.__in_memory:
return self.__data.columns.to_list()
else:
return data_get_columns(tmp_filename=self.__filename, file_type=self.__file_type)

def columns_delete(self, columns: list):
if self.__in_memory:
self.__data.drop(columns=columns, inplace=True)
else:
data_delete_columns(tmp_filename=self.__filename, file_type=self.__file_type, columns=columns)

return self

def columns(self) -> list:
if self.__in_memory:
return self.__data.columns.to_list()
else:
return data_get_columns(tmp_filename=self.__filename, file_type=self.__file_type)

def rename_columns(self, columns_mapping: dict):
def columns_rename(self, columns_mapping: dict):
if self.__in_memory:
self.__data.rename(columns=columns_mapping, inplace=True)
else:
Expand All @@ -182,8 +182,13 @@ def rename_columns(self, columns_mapping: dict):
)
return self

def select_columns(self, columns: list):
def columns_select(self, columns: list):
if self.__in_memory:
self.__data = self.__data[columns]
else:
data_select_columns(tmp_filename=self.__filename, file_type=self.__file_type, columns=columns)

# def filter_on_column(self, column: str, value: Any, operator: Operator):
# if self.__in_memory:
#
#
6 changes: 3 additions & 3 deletions tests/SequenceTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _sequence(self, data: DataFlow.DataFrame) -> None:

self.assertEqual(10, len(data.columns()))

data.del_columns(
data.columns_delete(
[
"Industry_aggregation_NZSIOC",
"Industry_code_NZSIOC",
Expand All @@ -25,10 +25,10 @@ def _sequence(self, data: DataFlow.DataFrame) -> None:
self.assertEqual(3, len(data.columns()))
self.assertListEqual(["Year", "Units", "Value"], data.columns())

data.rename_columns(columns_mapping={"Year": "_year_", "Units": "_units_"})
data.columns_rename(columns_mapping={"Year": "_year_", "Units": "_units_"})
self.assertListEqual(["_year_", "_units_", "Value"], data.columns())

data.select_columns(columns=["_year_"])
data.columns_select(columns=["_year_"])
self.assertListEqual(["_year_"], data.columns())

self.assertPandasEqual(
Expand Down

0 comments on commit bb38493

Please sign in to comment.