Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions hamilton/plugins/pandas_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,15 +1632,26 @@ class PandasTableReader(DataLoader):
def applicable_types(cls) -> Collection[type]:
return [DATAFRAME_TYPE]

def _get_loading_kwargs(self) -> dict[str, Any]:
# Puts kwargs in a dict
kwargs = dataclasses.asdict(self)
def _get_loading_kwargs(self) -> dict[str, Any]:
# Puts kwargs in a dict
kwargs = dataclasses.asdict(self)

# filepath_or_buffer corresponds to 'filepath_or_buffer' argument of pandas.read_table,
# but we send it separately
del kwargs["filepath_or_buffer"]

# Remove deprecated arguments for pandas >= 2.2
if Version(pd.__version__) >= Version("2.2"):
# verbose and keep_date_col were removed in pandas 2.2
kwargs.pop("verbose", None)
kwargs.pop("keep_date_col", None)
# delim_whitespace was removed in pandas 2.2; use sep=r"\s+" instead
delim_whitespace = kwargs.pop("delim_whitespace", None)
if delim_whitespace and kwargs.get("sep") == "\t":
kwargs["sep"] = r"\s+"

return kwargs

# filepath_or_buffer corresponds to 'filepath_or_buffer' argument of pandas.read_table,
# but we send it separately
del kwargs["filepath_or_buffer"]

return kwargs

def load_data(self, type_: type) -> tuple[DATAFRAME_TYPE, dict[str, Any]]:
# Loads the data and returns the df and metadata of the table
Expand Down