Skip to content

Commit a5bd2b7

Browse files
committed
fix: support multiple or no suffixes for type file
1 parent 6942b14 commit a5bd2b7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,5 @@ _site/
144144
objects.json
145145
reference/
146146
src/
147+
148+
/.luarc.json

pins/boards.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ def _pin_store(
248248
if type == "file":
249249
# the file type makes the name of the data the exact filename, rather
250250
# than the pin name + a suffix (e.g. my_pin.csv).
251-
object_name = Path(x).with_suffix("").name
251+
_p = Path(x)
252+
_base_len = len(_p.name) - len("".join(_p.suffixes))
253+
object_name = _p.name[:_base_len]
252254
else:
253255
object_name = None
254256

pins/tests/test_boards.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,38 @@ def test_board_pin_download(board_with_cache, tmp_path):
152152
board_with_cache.pin_read("cool_pin")
153153

154154

155+
def test_board_pin_download_filename_many_suffixes(board_with_cache, tmp_path):
156+
# create and save data
157+
df = pd.DataFrame({"x": [1, 2, 3]})
158+
159+
path = tmp_path / "data.a.b.csv"
160+
df.to_csv(path, index=False)
161+
162+
board_with_cache.pin_upload(path, "cool_pin")
163+
164+
(pin_path,) = board_with_cache.pin_download("cool_pin")
165+
assert Path(pin_path).name == "data.a.b.csv"
166+
167+
df = pd.read_csv(pin_path)
168+
assert df.x.tolist() == [1, 2, 3]
169+
170+
171+
def test_board_pin_download_filename_no_suffixes(board_with_cache, tmp_path):
172+
# create and save data
173+
df = pd.DataFrame({"x": [1, 2, 3]})
174+
175+
path = tmp_path / "data"
176+
df.to_csv(path, index=False)
177+
178+
board_with_cache.pin_upload(path, "cool_pin")
179+
180+
(pin_path,) = board_with_cache.pin_download("cool_pin")
181+
assert Path(pin_path).name == "data"
182+
183+
df = pd.read_csv(pin_path)
184+
assert df.x.tolist() == [1, 2, 3]
185+
186+
155187
def test_board_pin_download_filename(board_with_cache, tmp_path):
156188
# create and save data
157189
df = pd.DataFrame({"x": [1, 2, 3]})

0 commit comments

Comments
 (0)