Skip to content
Merged
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
12 changes: 6 additions & 6 deletions pins/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
REQUIRES_SINGLE_FILE = frozenset(["csv", "joblib", "file"])


def _assert_is_pandas_df(x):
def _assert_is_pandas_df(x, file_type: str) -> None:
import pandas as pd

if not isinstance(x, pd.DataFrame):
raise NotImplementedError(
"Currently only pandas.DataFrame can be saved to a CSV."
f"Currently only pandas.DataFrame can be saved as type {file_type!r}."
)


Expand Down Expand Up @@ -155,26 +155,26 @@ def save_data(
final_name = f"{fname}{suffix}"

if type == "csv":
_assert_is_pandas_df(obj)
_assert_is_pandas_df(obj, file_type=type)

obj.to_csv(final_name, index=False)

elif type == "arrow":
# NOTE: R pins accepts the type arrow, and saves it as feather.
# we allow reading this type, but raise an error for writing.
_assert_is_pandas_df(obj)
_assert_is_pandas_df(obj, file_type=type)

obj.to_feather(final_name)

elif type == "feather":
_assert_is_pandas_df(obj)
_assert_is_pandas_df(obj, file_type=type)

raise NotImplementedError(
'Saving data as type "feather" no longer supported. Use type "arrow" instead.'
)

elif type == "parquet":
_assert_is_pandas_df(obj)
_assert_is_pandas_df(obj, file_type=type)

obj.to_parquet(final_name)

Expand Down