Skip to content

Commit f3ea387

Browse files
Tailor _assert_is_pandas_df error - not just CSV but for all file t… (#268)
1 parent cda3b33 commit f3ea387

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pins/drivers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
REQUIRES_SINGLE_FILE = frozenset(["csv", "joblib", "file"])
1515

1616

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

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

2525

@@ -153,26 +153,26 @@ def save_data(obj, fname, type=None, apply_suffix: bool = True) -> "str | Sequen
153153
final_name = f"{fname}{suffix}"
154154

155155
if type == "csv":
156-
_assert_is_pandas_df(obj)
156+
_assert_is_pandas_df(obj, file_type=type)
157157

158158
obj.to_csv(final_name, index=False)
159159

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

165165
obj.to_feather(final_name)
166166

167167
elif type == "feather":
168-
_assert_is_pandas_df(obj)
168+
_assert_is_pandas_df(obj, file_type=type)
169169

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

174174
elif type == "parquet":
175-
_assert_is_pandas_df(obj)
175+
_assert_is_pandas_df(obj, file_type=type)
176176

177177
obj.to_parquet(final_name)
178178

0 commit comments

Comments
 (0)