File tree Expand file tree Collapse file tree 5 files changed +43
-3
lines changed
tests/pins-old-types/a-table/v Expand file tree Collapse file tree 5 files changed +43
-3
lines changed Original file line number Diff line number Diff line change 1313
1414
1515UNSAFE_TYPES = frozenset (["joblib" ])
16+ REQUIRES_SINGLE_FILE = frozenset (["csv" , "joblib" , "file" ])
1617
1718
1819def 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
Original file line number Diff line number Diff line change 1+ "a","b"
2+ 1,"x"
3+ 2,"y"
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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" )
You can’t perform that action at this time.
0 commit comments