Skip to content

Commit 8b66245

Browse files
authored
Merge pull request #87 from machow/feat-driver-table-type
Feat driver table type
2 parents 4fcc39b + 24f9903 commit 8b66245

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

pins/drivers.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
UNSAFE_TYPES = frozenset(["joblib"])
16+
REQUIRES_SINGLE_FILE = frozenset(["csv", "joblib", "file"])
1617

1718

1819
def load_data(
@@ -44,21 +45,35 @@ def load_data(
4445

4546
# Check that only a single file name was given
4647
fnames = [meta.file] if isinstance(meta.file, str) else meta.file
47-
if len(fnames) > 1:
48+
if len(fnames) > 1 and type in REQUIRES_SINGLE_FILE:
4849
raise ValueError("Cannot load data when more than 1 file")
4950

50-
# TODO: currently only can load a single file
51-
target_fname = fnames[0]
51+
# file path creation ------------------------------------------------------
52+
53+
if type == "table":
54+
# this type contains an rds and csv files named data.{ext}, so we match
55+
# R pins behavior and hardcode the name
56+
target_fname = "data.csv"
57+
else:
58+
target_fname = fnames[0]
59+
5260
if path_to_version is not None:
5361
path_to_file = f"{path_to_version}/{target_fname}"
5462
else:
5563
path_to_file = target_fname
5664

65+
# type handling -----------------------------------------------------------
66+
5767
if meta.type == "csv":
5868
import pandas as pd
5969

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

72+
elif meta.type == "table":
73+
import pandas as pd
74+
75+
return pd.read_csv(fs.open(path_to_file))
76+
6277
elif meta.type == "joblib":
6378
import joblib
6479

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"a","b"
2+
1,"x"
3+
2,"y"
116 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
path:
2+
- data.csv
3+
- data.rds
4+
type: table
5+
rows: 2
6+
cols: 2
7+
columns:
8+
a: integer
9+
b: character

script/stage_r_pins_old_types.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cache = tempfile()
2+
board_register_local(cache = cache)
3+
4+
some_df = data.frame(a = 1:2, b = c("x","y"))
5+
pin(some_df, name="a-table")
6+
7+
# note that pin automatically changes _ to -
8+
# TODO: for now manually copying into pins/tests/pins-old-types
9+
# Note that a trivial version name, v, is used to check the reading behavior
10+
# since pins v0 does not save versions
11+
# >>> mkdir pins/tests/pins-old-types/a-table/v/
12+
# >>> cp -r <path_to_pin> pins/tests/pins-old-types/a-table/v/
13+
fs::path(cache, "a-table")

0 commit comments

Comments
 (0)