Get an appropriately typed and shaped pytables.Col object for values.
(cls, values: ArrayLike)
| 2569 | |
| 2570 | @classmethod |
| 2571 | def _get_atom(cls, values: ArrayLike) -> Col: |
| 2572 | """ |
| 2573 | Get an appropriately typed and shaped pytables.Col object for values. |
| 2574 | """ |
| 2575 | dtype = values.dtype |
| 2576 | # error: Item "ExtensionDtype" of "Union[ExtensionDtype, dtype[Any]]" has no |
| 2577 | # attribute "itemsize" |
| 2578 | itemsize = dtype.itemsize # type: ignore[union-attr] |
| 2579 | |
| 2580 | shape = values.shape |
| 2581 | if values.ndim == 1: |
| 2582 | # EA, use block shape pretending it is 2D |
| 2583 | # TODO(EA2D): not necessary with 2D EAs |
| 2584 | shape = (1, values.size) |
| 2585 | |
| 2586 | if isinstance(values, Categorical): |
| 2587 | codes = values.codes |
| 2588 | atom = cls.get_atom_data(shape, kind=codes.dtype.name) |
| 2589 | elif lib.is_np_dtype(dtype, "M") or isinstance(dtype, DatetimeTZDtype): |
| 2590 | atom = cls.get_atom_datetime64(shape) |
| 2591 | elif lib.is_np_dtype(dtype, "m"): |
| 2592 | atom = cls.get_atom_timedelta64(shape) |
| 2593 | elif is_complex_dtype(dtype): |
| 2594 | atom = _tables().ComplexCol(itemsize=itemsize, shape=shape[0]) |
| 2595 | elif is_string_dtype(dtype): |
| 2596 | atom = cls.get_atom_string(shape, itemsize) |
| 2597 | else: |
| 2598 | atom = cls.get_atom_data(shape, kind=dtype.name) |
| 2599 | |
| 2600 | return atom |
| 2601 | |
| 2602 | @classmethod |
| 2603 | def get_atom_string(cls, shape, itemsize): |
no test coverage detected