|
7 | 7 | from importlib.metadata import version |
8 | 8 | from itertools import product |
9 | 9 | from types import MappingProxyType |
10 | | -from typing import TYPE_CHECKING |
| 10 | +from typing import TYPE_CHECKING, Protocol |
11 | 11 | from warnings import warn |
12 | 12 |
|
13 | 13 | import h5py |
|
46 | 46 | from .registry import _REGISTRY, IOSpec, read_elem, read_elem_partial |
47 | 47 |
|
48 | 48 | if TYPE_CHECKING: |
49 | | - from collections.abc import Callable, Iterator |
| 49 | + from collections.abc import Iterator |
50 | 50 | from os import PathLike |
51 | 51 | from typing import Any, Literal |
52 | 52 |
|
@@ -443,7 +443,7 @@ def write_basic( |
443 | 443 | dataset_kwargs: Mapping[str, Any] = MappingProxyType({}), |
444 | 444 | ): |
445 | 445 | """Write methods which underlying library handles natively.""" |
446 | | - dataset_kwargs = dataset_kwargs.copy() |
| 446 | + dataset_kwargs = dict(dataset_kwargs) |
447 | 447 | dtype = dataset_kwargs.pop("dtype", elem.dtype) |
448 | 448 | if isinstance(f, H5Group) or is_zarr_v2(): |
449 | 449 | f.create_dataset(k, data=elem, shape=elem.shape, dtype=dtype, **dataset_kwargs) |
@@ -525,7 +525,7 @@ def write_basic_dask_dask_dense( |
525 | 525 | ): |
526 | 526 | import dask.array as da |
527 | 527 |
|
528 | | - dataset_kwargs = dataset_kwargs.copy() |
| 528 | + dataset_kwargs = dict(dataset_kwargs) |
529 | 529 | is_h5 = isinstance(f, H5Group) |
530 | 530 | if not is_h5: |
531 | 531 | dataset_kwargs = zarr_v3_compressor_compat(dataset_kwargs) |
@@ -629,7 +629,7 @@ def write_vlen_string_array_zarr( |
629 | 629 | from numcodecs import VLenUTF8 |
630 | 630 | from zarr.core.dtype import VariableLengthUTF8 |
631 | 631 |
|
632 | | - dataset_kwargs = dataset_kwargs.copy() |
| 632 | + dataset_kwargs = dict(dataset_kwargs) |
633 | 633 | dataset_kwargs = zarr_v3_compressor_compat(dataset_kwargs) |
634 | 634 | dtype = VariableLengthUTF8() |
635 | 635 | filters, fill_value = None, None |
@@ -702,7 +702,7 @@ def write_recarray_zarr( |
702 | 702 | if is_zarr_v2(): |
703 | 703 | f.create_dataset(k, data=elem, shape=elem.shape, **dataset_kwargs) |
704 | 704 | else: |
705 | | - dataset_kwargs = dataset_kwargs.copy() |
| 705 | + dataset_kwargs = dict(dataset_kwargs) |
706 | 706 | dataset_kwargs = zarr_v3_compressor_compat(dataset_kwargs) |
707 | 707 | # https://github.com/zarr-developers/zarr-python/issues/3546 |
708 | 708 | # if "shards" not in dataset_kwargs and ad.settings.auto_shard_zarr_v3: |
@@ -1210,14 +1210,14 @@ def write_nullable( |
1210 | 1210 | )(write_nullable) |
1211 | 1211 |
|
1212 | 1212 |
|
| 1213 | +class _BaseMaskedArray(Protocol): |
| 1214 | + def __call__( |
| 1215 | + self, values: NDArray[np.number], /, *, mask: NDArray[np.bool_] |
| 1216 | + ) -> pd.api.extensions.ExtensionArray: ... |
| 1217 | + |
| 1218 | + |
1213 | 1219 | def _read_nullable( |
1214 | | - elem: GroupStorageType, |
1215 | | - *, |
1216 | | - _reader: Reader, |
1217 | | - # BaseMaskedArray |
1218 | | - array_type: Callable[ |
1219 | | - [NDArray[np.number], NDArray[np.bool_]], pd.api.extensions.ExtensionArray |
1220 | | - ], |
| 1220 | + elem: GroupStorageType, *, _reader: Reader, array_type: _BaseMaskedArray |
1221 | 1221 | ) -> pd.api.extensions.ExtensionArray: |
1222 | 1222 | return array_type( |
1223 | 1223 | _reader.read_elem(elem["values"]), |
@@ -1378,7 +1378,7 @@ def write_string( |
1378 | 1378 | _writer: Writer, |
1379 | 1379 | dataset_kwargs: Mapping[str, Any], |
1380 | 1380 | ): |
1381 | | - dataset_kwargs = dataset_kwargs.copy() |
| 1381 | + dataset_kwargs = dict(dataset_kwargs) |
1382 | 1382 | dataset_kwargs.pop("compression", None) |
1383 | 1383 | dataset_kwargs.pop("compression_opts", None) |
1384 | 1384 | f.create_dataset( |
|
0 commit comments