Skip to content

Commit

Permalink
Remove types_from_dataframe function, since unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ezander committed Jun 24, 2024
1 parent 3a9a667 commit b9bac1c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions mokapot/tabular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ def get_chunked_data_iterator(
yield self._get_mapped_dataframe(chunk)


def _types_from_dataframe(df: pd.DataFrame) -> list:
type_map = df.dtypes
column_names = df.columns.tolist()
return [type_map[column_name] for column_name in column_names]


@typechecked
class CSVFileReader(TabularDataReader):
def __init__(self, file_name: Path, sep: str = "\t"):
Expand All @@ -165,7 +159,7 @@ def get_column_names(self) -> list[str]:

def get_column_types(self) -> list:
df = pd.read_csv(self.file_name, **self.stdargs, nrows=2)
return _types_from_dataframe(df)
return df.dtypes.tolist()

def read(self, columns: list[str] | None = None) -> pd.DataFrame:
result = pd.read_csv(self.file_name, usecols=columns, **self.stdargs)
Expand Down Expand Up @@ -200,7 +194,7 @@ def get_column_names(self) -> list[str]:
return self.df.columns.tolist()

def get_column_types(self) -> list:
return _types_from_dataframe(self.df)
return self.df.dtypes.tolist()

def read(self, columns: list[str] | None = None) -> pd.DataFrame:
return self.df if columns is None else self.df[columns]
Expand Down Expand Up @@ -297,7 +291,7 @@ def check_valid_data(self, data: pd.DataFrame):
# todo: Commented out for a while till we have a better type
# compatibility check, or agreed on some "super type" of numpy
# dtype and pyarrow types (and what not...)
# column_types = _types_from_dataframe(data)
# column_types = data.dtypes.tolist()
# if not column_types == self.get_column_types():
# raise ValueError(
# f"Column types {column_types} do not match {self.get_column_types()}"
Expand Down

0 comments on commit b9bac1c

Please sign in to comment.