Skip to content

Commit 6942b14

Browse files
committed
fix: do not support type file in pin_write
1 parent 3c850e5 commit 6942b14

File tree

2 files changed

+55
-33
lines changed

2 files changed

+55
-33
lines changed

pins/boards.py

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def pin_read(self, name, version: Optional[str] = None, hash: Optional[str] = No
225225
meta, self.construct_path([pin_name, meta.version.version])
226226
)
227227

228-
def pin_write(
228+
def _pin_store(
229229
self,
230230
x,
231231
name: Optional[str] = None,
@@ -236,32 +236,6 @@ def pin_write(
236236
versioned: Optional[bool] = None,
237237
created: Optional[datetime] = None,
238238
) -> Meta:
239-
"""Write a pin object to the board.
240-
241-
Parameters
242-
----------
243-
x:
244-
An object (e.g. a pandas DataFrame) to pin.
245-
name:
246-
Pin name.
247-
type:
248-
File type used to save `x` to disk. May be "csv", "arrow", "parquet",
249-
"joblib", "json", or "file".
250-
title:
251-
A title for the pin; most important for shared boards so that others
252-
can understand what the pin contains. If omitted, a brief description
253-
of the contents will be automatically generated.
254-
description:
255-
A detailed description of the pin contents.
256-
metadata:
257-
A dictionary containing additional metadata to store with the pin.
258-
This gets stored on the Meta.user field.
259-
versioned:
260-
Whether the pin should be versioned. Defaults to versioning.
261-
created:
262-
A date to store in the Meta.created field. This field may be used as
263-
part of the pin version name.
264-
"""
265239

266240
if type == "feather":
267241
warn_deprecated(
@@ -334,6 +308,54 @@ def pin_write(
334308

335309
return meta
336310

311+
def pin_write(
312+
self,
313+
x,
314+
name: Optional[str] = None,
315+
type: Optional[str] = None,
316+
title: Optional[str] = None,
317+
description: Optional[str] = None,
318+
metadata: Optional[Mapping] = None,
319+
versioned: Optional[bool] = None,
320+
created: Optional[datetime] = None,
321+
) -> Meta:
322+
"""Write a pin object to the board.
323+
324+
Parameters
325+
----------
326+
x:
327+
An object (e.g. a pandas DataFrame) to pin.
328+
name:
329+
Pin name.
330+
type:
331+
File type used to save `x` to disk. May be "csv", "arrow", "parquet",
332+
"joblib", "json", or "file".
333+
title:
334+
A title for the pin; most important for shared boards so that others
335+
can understand what the pin contains. If omitted, a brief description
336+
of the contents will be automatically generated.
337+
description:
338+
A detailed description of the pin contents.
339+
metadata:
340+
A dictionary containing additional metadata to store with the pin.
341+
This gets stored on the Meta.user field.
342+
versioned:
343+
Whether the pin should be versioned. Defaults to versioning.
344+
created:
345+
A date to store in the Meta.created field. This field may be used as
346+
part of the pin version name.
347+
"""
348+
349+
if type == "file":
350+
raise NotImplementedError(
351+
".pin_write() does not support type='file'. "
352+
"Use .pin_upload() to save a file as a pin."
353+
)
354+
355+
return self._pin_store(
356+
x, name, type, title, description, metadata, versioned, created
357+
)
358+
337359
def pin_download(self, name, version=None, hash=None) -> Sequence[str]:
338360
"""Download the files contained in a pin.
339361
@@ -380,7 +402,7 @@ def pin_upload(self, paths, name=None, title=None, description=None, metadata=No
380402
using [](`~pins.boards.BaseBoard.pin_download`).
381403
"""
382404

383-
return self.pin_write(
405+
return self._pin_store(
384406
paths,
385407
name,
386408
type="file",

pins/tests/test_boards.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,15 @@ def test_board_pin_write_feather_deprecated(board):
123123
board.pin_write(df, "cool_pin", type="feather")
124124

125125

126-
def test_board_pin_write_file(board, tmp_path):
126+
def test_board_pin_write_file_raises_error(board, tmp_path):
127127
df = pd.DataFrame({"x": [1, 2, 3]})
128128

129129
path = tmp_path.joinpath("data.csv")
130130
df.to_csv(path, index=False)
131131

132132
# TODO: should this error?
133-
meta = board.pin_write(path, "cool_pin", type="file")
134-
assert meta.type == "file"
135-
136133
with pytest.raises(NotImplementedError):
137-
(pin_path,) = board.pin_read("cool_pin")
134+
board.pin_write(path, "cool_pin", type="file")
138135

139136

140137
def test_board_pin_download(board_with_cache, tmp_path):
@@ -151,6 +148,9 @@ def test_board_pin_download(board_with_cache, tmp_path):
151148
df = pd.read_csv(pin_path)
152149
assert df.x.tolist() == [1, 2, 3]
153150

151+
with pytest.raises(NotImplementedError):
152+
board_with_cache.pin_read("cool_pin")
153+
154154

155155
def test_board_pin_download_filename(board_with_cache, tmp_path):
156156
# create and save data

0 commit comments

Comments
 (0)