Internal implementation for reading a Feather file as a pyarrow.Table. Does not emit deprecation warnings.
(source, columns=None, memory_map=False,
use_threads=True)
| 262 | |
| 263 | |
| 264 | def _read_table_internal(source, columns=None, memory_map=False, |
| 265 | use_threads=True): |
| 266 | """ |
| 267 | Internal implementation for reading a Feather file as a pyarrow.Table. |
| 268 | Does not emit deprecation warnings. |
| 269 | """ |
| 270 | reader = _feather.FeatherReader( |
| 271 | source, use_memory_map=memory_map, use_threads=use_threads) |
| 272 | |
| 273 | if columns is None: |
| 274 | return reader.read() |
| 275 | |
| 276 | if not isinstance(columns, Sequence): |
| 277 | raise TypeError("Columns must be a sequence but, got {}" |
| 278 | .format(type(columns).__name__)) |
| 279 | |
| 280 | column_types = [type(column) for column in columns] |
| 281 | if all(map(lambda t: t == int, column_types)): |
| 282 | table = reader.read_indices(columns) |
| 283 | elif all(map(lambda t: t == str, column_types)): |
| 284 | table = reader.read_names(columns) |
| 285 | else: |
| 286 | column_type_names = [t.__name__ for t in column_types] |
| 287 | raise TypeError("Columns must be indices or names. " |
| 288 | f"Got columns {columns} of types {column_type_names}") |
| 289 | |
| 290 | # Feather v1 already respects the column selection |
| 291 | if reader.version < 3: |
| 292 | return table |
| 293 | # Feather v2 reads with sorted / deduplicated selection |
| 294 | elif sorted(set(columns)) == columns: |
| 295 | return table |
| 296 | else: |
| 297 | # follow exact order / selection of names |
| 298 | return table.select(columns) |
| 299 | |
| 300 | |
| 301 | def read_table(source, columns=None, memory_map=False, use_threads=True): |