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

Function read_table

python/pyarrow/feather.py:230–279  ·  view source on GitHub ↗

Read a pyarrow.Table from Feather format Parameters ---------- source : str file path, or file-like object You can use MemoryMappedFile as source, for explicitly use memory map. columns : sequence, optional Only read a specific set of columns. If not provided, a

(source, columns=None, memory_map=False, use_threads=True)

Source from the content-addressed store, hash-verified

228
229
230def read_table(source, columns=None, memory_map=False, use_threads=True):
231 """
232 Read a pyarrow.Table from Feather format
233
234 Parameters
235 ----------
236 source : str file path, or file-like object
237 You can use MemoryMappedFile as source, for explicitly use memory map.
238 columns : sequence, optional
239 Only read a specific set of columns. If not provided, all columns are
240 read.
241 memory_map : boolean, default False
242 Use memory mapping when opening file on disk, when source is a str
243 use_threads : bool, default True
244 Whether to parallelize reading using multiple threads.
245
246 Returns
247 -------
248 table : pyarrow.Table
249 The contents of the Feather file as a pyarrow.Table
250 """
251 reader = _feather.FeatherReader(
252 source, use_memory_map=memory_map, use_threads=use_threads)
253
254 if columns is None:
255 return reader.read()
256
257 if not isinstance(columns, Sequence):
258 raise TypeError("Columns must be a sequence but, got {}"
259 .format(type(columns).__name__))
260
261 column_types = [type(column) for column in columns]
262 if all(map(lambda t: t == int, column_types)):
263 table = reader.read_indices(columns)
264 elif all(map(lambda t: t == str, column_types)):
265 table = reader.read_names(columns)
266 else:
267 column_type_names = [t.__name__ for t in column_types]
268 raise TypeError("Columns must be indices or names. "
269 f"Got columns {columns} of types {column_type_names}")
270
271 # Feather v1 already respects the column selection
272 if reader.version < 3:
273 return table
274 # Feather v2 reads with sorted / deduplicated selection
275 elif sorted(set(columns)) == columns:
276 return table
277 else:
278 # follow exact order / selection of names
279 return table.select(columns)

Calls 6

mapFunction · 0.85
TypeErrorFunction · 0.50
typeEnum · 0.50
readMethod · 0.45
formatMethod · 0.45
selectMethod · 0.45