Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion pins/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .meta import Meta, MetaRaw, MetaFactory
from .errors import PinsError
from .drivers import load_data, save_data, default_title
from .utils import inform, ExtendMethodDoc
from .utils import inform, warn_deprecated, ExtendMethodDoc
from .config import get_allow_rsc_short_name


Expand Down Expand Up @@ -255,6 +255,14 @@ def pin_write(
part of the pin version name.
"""

if type == "feather":
warn_deprecated(
'Writing pin type "feather" is unsupported. Switching type to "arrow".'
" This produces the exact same behavior, and also works with R pins."
' Please switch to pin_write using type="arrow".'
)
type = "arrow"

pin_name = self.path_to_pin(name)

# TODO(docs): describe options for type argument
Expand Down
16 changes: 15 additions & 1 deletion pins/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def load_data(

return pd.read_csv(fs.open(path_to_file))

elif meta.type == "arrow":
import pandas as pd

return pd.read_feather(fs.open(path_to_file))

elif meta.type == "feather":
import pandas as pd

Expand Down Expand Up @@ -123,11 +128,20 @@ def save_data(

obj.to_csv(final_name, index=False)

elif type == "feather":
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)

obj.to_feather(final_name)

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

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

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

Expand Down
7 changes: 7 additions & 0 deletions pins/tests/test_boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class C:
assert "MY_TYPE" in exc_info.value.args[0]


def test_board_pin_write_feather_deprecated(board):
df = pd.DataFrame({"x": [1, 2, 3]})

with pytest.warns(DeprecationWarning):
board.pin_write(df, "cool_pin", type="feather")


def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
if board.fs.protocol != "rsc":
pytest.skip()
Expand Down
38 changes: 33 additions & 5 deletions pins/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def test_default_title(obj, dst_title):
"type_",
[
"csv",
"feather",
"arrow",
"parquet",
"joblib",
],
)
def test_driver_roundtrip(tmp_dir2, type_):
Expand All @@ -71,14 +72,41 @@ def test_driver_roundtrip(tmp_dir2, type_):
assert Path(res_fname).name == full_file

meta = MetaRaw(full_file, type_, "my_pin")
obj = load_data(meta, fsspec.filesystem("file"), tmp_dir2)
obj = load_data(meta, fsspec.filesystem("file"), tmp_dir2, allow_pickle_read=True)

assert df.equals(obj)


@pytest.mark.skip("TODO: complete once driver story is fleshed out")
def test_driver_roundtrip_joblib(tmp_dir2):
pass
def test_driver_feather_write_error(tmp_dir2):
import pandas as pd

df = pd.DataFrame({"x": [1, 2, 3]})

fname = "some_df"

p_obj = tmp_dir2 / fname

with pytest.raises(NotImplementedError) as exc_info:
save_data(df, p_obj, "feather")

assert '"feather" no longer supported.' in exc_info.value.args[0]


def test_driver_feather_read_backwards_compat(tmp_dir2):
import pandas as pd

df = pd.DataFrame({"x": [1, 2, 3]})

fname = "some_df"
full_file = f"{fname}.feather"

df.to_feather(tmp_dir2 / full_file)

obj = load_data(
MetaRaw(full_file, "feather", "my_pin"), fsspec.filesystem("file"), tmp_dir2
)

assert df.equals(obj)


def test_driver_pickle_read_fail_explicit(some_joblib):
Expand Down
5 changes: 5 additions & 0 deletions pins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from functools import update_wrapper
from types import MethodType
from warnings import warn

from .config import pins_options

Expand All @@ -14,6 +15,10 @@ def inform(log, msg):
print(msg, file=sys.stderr)


def warn_deprecated(msg):
warn(msg, DeprecationWarning)


class ExtendMethodDoc:
# Note that the indentation assumes these are top-level method docstrings,
# so are indented 8 spaces (after the initial sentence).
Expand Down