|
18 | 18 |
|
19 | 19 | from zarr.abc.codec import Codec |
20 | 20 | from zarr.api.asynchronous import ArrayLike, PathLike |
| 21 | + from zarr.core.array import CompressorsParam, FiltersParam |
21 | 22 | from zarr.core.array_spec import ArrayConfig, ArrayConfigParams |
22 | 23 | from zarr.core.buffer import NDArrayLike |
23 | | - from zarr.core.chunk_key_encodings import ChunkKeyEncoding |
24 | | - from zarr.core.common import JSON, AccessModeLiteral, ChunkCoords, MemoryOrder, ZarrFormat |
| 24 | + from zarr.core.chunk_key_encodings import ChunkKeyEncoding, ChunkKeyEncodingParams |
| 25 | + from zarr.core.common import ( |
| 26 | + JSON, |
| 27 | + AccessModeLiteral, |
| 28 | + ChunkCoords, |
| 29 | + MemoryOrder, |
| 30 | + ShapeLike, |
| 31 | + ZarrFormat, |
| 32 | + ) |
25 | 33 | from zarr.storage import StoreLike |
26 | 34 |
|
27 | 35 | __all__ = [ |
@@ -700,8 +708,138 @@ def create( |
700 | 708 | ) |
701 | 709 |
|
702 | 710 |
|
703 | | -def create_array(*args: Any, **kwargs: Any) -> Array: |
704 | | - return Array(sync(zarr.core.array.create_array(*args, **kwargs))) |
| 711 | +def create_array( |
| 712 | + store: str | StoreLike, |
| 713 | + *, |
| 714 | + name: str | None = None, |
| 715 | + shape: ShapeLike, |
| 716 | + dtype: npt.DTypeLike, |
| 717 | + chunks: ChunkCoords | Literal["auto"] = "auto", |
| 718 | + shards: ChunkCoords | Literal["auto"] | None = None, |
| 719 | + filters: FiltersParam = "auto", |
| 720 | + compressors: CompressorsParam = "auto", |
| 721 | + fill_value: Any | None = None, |
| 722 | + order: MemoryOrder | None = None, |
| 723 | + zarr_format: ZarrFormat | None = 3, |
| 724 | + attributes: dict[str, JSON] | None = None, |
| 725 | + chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingParams | None = None, |
| 726 | + dimension_names: Iterable[str] | None = None, |
| 727 | + storage_options: dict[str, Any] | None = None, |
| 728 | + overwrite: bool = False, |
| 729 | + config: ArrayConfig | ArrayConfigParams | None = None, |
| 730 | +) -> Array: |
| 731 | + """Create an ``Array``. This function wraps :mod:`zarr.core.array.create_array`. |
| 732 | +
|
| 733 | + Parameters |
| 734 | + ---------- |
| 735 | + store : str or Store |
| 736 | + Store or path to directory in file system or name of zip file. |
| 737 | + name : str or None, optional |
| 738 | + The name of the array within the store. If ``name`` is ``None``, the array will be located |
| 739 | + at the root of the store. |
| 740 | + shape : ChunkCoords |
| 741 | + Shape of the array. |
| 742 | + dtype : npt.DTypeLike |
| 743 | + Data type of the array. |
| 744 | + chunks : ChunkCoords, optional |
| 745 | + Chunk shape of the array. |
| 746 | + If not specified, default are guessed based on the shape and dtype. |
| 747 | + shards : ChunkCoords, optional |
| 748 | + Shard shape of the array. The default value of ``None`` results in no sharding at all. |
| 749 | + filters : Iterable[Codec], optional |
| 750 | + Iterable of filters to apply to each chunk of the array, in order, before serializing that |
| 751 | + chunk to bytes. |
| 752 | +
|
| 753 | + For Zarr v3, a "filter" is a codec that takes an array and returns an array, |
| 754 | + and these values must be instances of ``ArrayArrayCodec``, or dict representations |
| 755 | + of ``ArrayArrayCodec``. |
| 756 | + If ``filters`` and ``compressors`` are not specified, then the default codecs for |
| 757 | + Zarr v3 will be used. |
| 758 | + These defaults can be changed by modifying the value of ``array.v3_default_codecs`` |
| 759 | + in :mod:`zarr.core.config`. |
| 760 | + Use ``None`` to omit default filters. |
| 761 | +
|
| 762 | + For Zarr v2, a "filter" can be any numcodecs codec; you should ensure that the |
| 763 | + the order if your filters is consistent with the behavior of each filter. |
| 764 | + If no ``filters`` are provided, a default set of filters will be used. |
| 765 | + These defaults can be changed by modifying the value of ``array.v2_default_filters`` |
| 766 | + in :mod:`zarr.core.config`. |
| 767 | + Use ``None`` to omit default filters. |
| 768 | + compressors : Iterable[Codec], optional |
| 769 | + List of compressors to apply to the array. Compressors are applied in order, and after any |
| 770 | + filters are applied (if any are specified). |
| 771 | +
|
| 772 | + For Zarr v3, a "compressor" is a codec that takes a bytestrea, and |
| 773 | + returns another bytestream. Multiple compressors my be provided for Zarr v3. |
| 774 | + If ``filters`` and ``compressors`` are not specified, then the default codecs for |
| 775 | + Zarr v3 will be used. |
| 776 | + These defaults can be changed by modifying the value of ``array.v3_default_codecs`` |
| 777 | + in :mod:`zarr.core.config`. |
| 778 | + Use ``None`` to omit default compressors. |
| 779 | +
|
| 780 | + For Zarr v2, a "compressor" can be any numcodecs codec. Only a single compressor may |
| 781 | + be provided for Zarr v2. |
| 782 | + If no ``compressors`` are provided, a default compressor will be used. |
| 783 | + These defaults can be changed by modifying the value of ``array.v2_default_compressor`` |
| 784 | + in :mod:`zarr.core.config`. |
| 785 | + Use ``None`` to omit the default compressor. |
| 786 | + fill_value : Any, optional |
| 787 | + Fill value for the array. |
| 788 | + order : {"C", "F"}, optional |
| 789 | + The memory of the array (default is "C"). |
| 790 | + For Zarr v2, this parameter sets the memory order of the array. |
| 791 | + For Zarr v3, this parameter is deprecated, because memory order |
| 792 | + is a runtime parameter for Zarr v3 arrays. The recommended way to specify the memory |
| 793 | + order for Zarr v3 arrays is via the ``config`` parameter, e.g. ``{'config': 'C'}``. |
| 794 | + If no ``order`` is provided, a default order will be used. |
| 795 | + This default can be changed by modifying the value of ``array.order`` in :mod:`zarr.core.config`. |
| 796 | + zarr_format : {2, 3}, optional |
| 797 | + The zarr format to use when saving. |
| 798 | + attributes : dict, optional |
| 799 | + Attributes for the array. |
| 800 | + chunk_key_encoding : ChunkKeyEncoding, optional |
| 801 | + A specification of how the chunk keys are represented in storage. |
| 802 | + For Zarr v3, the default is ``{"name": "default", "separator": "/"}}``. |
| 803 | + For Zarr v2, the default is ``{"name": "v2", "separator": "."}}``. |
| 804 | + dimension_names : Iterable[str], optional |
| 805 | + The names of the dimensions (default is None). |
| 806 | + Zarr v3 only. Zarr v2 arrays should not use this parameter. |
| 807 | + storage_options : dict, optional |
| 808 | + If using an fsspec URL to create the store, these will be passed to the backend implementation. |
| 809 | + Ignored otherwise. |
| 810 | + overwrite : bool, default False |
| 811 | + Whether to overwrite an array with the same name in the store, if one exists. |
| 812 | + config : ArrayConfig or ArrayConfigParams, optional |
| 813 | + Runtime configuration for the array. |
| 814 | +
|
| 815 | + Returns |
| 816 | + ------- |
| 817 | + z : Array |
| 818 | + The array. |
| 819 | + """ |
| 820 | + return Array( |
| 821 | + sync( |
| 822 | + zarr.core.array.create_array( |
| 823 | + store, |
| 824 | + name=name, |
| 825 | + shape=shape, |
| 826 | + dtype=dtype, |
| 827 | + chunks=chunks, |
| 828 | + shards=shards, |
| 829 | + filters=filters, |
| 830 | + compressors=compressors, |
| 831 | + fill_value=fill_value, |
| 832 | + order=order, |
| 833 | + zarr_format=zarr_format, |
| 834 | + attributes=attributes, |
| 835 | + chunk_key_encoding=chunk_key_encoding, |
| 836 | + dimension_names=dimension_names, |
| 837 | + storage_options=storage_options, |
| 838 | + overwrite=overwrite, |
| 839 | + config=config, |
| 840 | + ) |
| 841 | + ) |
| 842 | + ) |
705 | 843 |
|
706 | 844 |
|
707 | 845 | # TODO: add type annotations for kwargs |
|
0 commit comments