MCPcopy Create free account
hub / github.com/apache/arrow / FeatherDataset

Class FeatherDataset

python/pyarrow/feather.py:31–94  ·  view source on GitHub ↗

Encapsulates details of reading a list of Feather files. Parameters ---------- path_or_paths : List[str] A list of file names validate_schema : bool, default True Check that individual file schemas are all the same / compatible

Source from the content-addressed store, hash-verified

29
30
31class FeatherDataset:
32 """
33 Encapsulates details of reading a list of Feather files.
34
35 Parameters
36 ----------
37 path_or_paths : List[str]
38 A list of file names
39 validate_schema : bool, default True
40 Check that individual file schemas are all the same / compatible
41 """
42
43 def __init__(self, path_or_paths, validate_schema=True):
44 self.paths = path_or_paths
45 self.validate_schema = validate_schema
46
47 def read_table(self, columns=None):
48 """
49 Read multiple feather files as a single pyarrow.Table
50
51 Parameters
52 ----------
53 columns : List[str]
54 Names of columns to read from the file
55
56 Returns
57 -------
58 pyarrow.Table
59 Content of the file as a table (of columns)
60 """
61 _fil = _read_table_internal(self.paths[0], columns=columns)
62 self._tables = [_fil]
63 self.schema = _fil.schema
64
65 for path in self.paths[1:]:
66 table = _read_table_internal(path, columns=columns)
67 if self.validate_schema:
68 self.validate_schemas(path, table)
69 self._tables.append(table)
70 return concat_tables(self._tables)
71
72 def validate_schemas(self, piece, table):
73 if not self.schema.equals(table.schema):
74 raise ValueError(f'Schema in {piece} was different. \n'
75 f'{self.schema}\n\nvs\n\n{table.schema}')
76
77 def read_pandas(self, columns=None, use_threads=True):
78 """
79 Read multiple Parquet files as a single pandas DataFrame
80
81 Parameters
82 ----------
83 columns : List[str]
84 Names of columns to read from the file
85 use_threads : bool, default True
86 Use multiple threads when converting to pandas
87
88 Returns

Callers 2

test_datasetFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_datasetFunction · 0.72