From 58f14ee10b7d78f553ad28c1214510855393a6fb Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Tue, 9 Jul 2024 19:52:42 -0400 Subject: [PATCH 1/5] Add Zarr v3 dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 9fe0468a..c5498f67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ dependencies = [ "ujson", "packaging", "universal-pathlib", + "zarr>=3.0.0a0" ] [project.optional-dependencies] From 5f9a88f2116956781107c4be0a0ec23a6dfe0482 Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Tue, 9 Jul 2024 20:11:15 -0400 Subject: [PATCH 2/5] Add documentation --- docs/releases.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/releases.rst b/docs/releases.rst index c44ff245..0fc63dab 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -12,6 +12,9 @@ New Features Breaking changes ~~~~~~~~~~~~~~~~ +- Requires Zarr 3.0 (for :pull:`182`). + By `Tom Nicholas `_. + Deprecations ~~~~~~~~~~~~ From aa2129949d858b3b0d50382ed963f3e73bc25a49 Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Tue, 9 Jul 2024 21:20:22 -0400 Subject: [PATCH 3/5] Update docs/releases.rst Slopy copy-paste, thank you Tom Co-authored-by: Tom Nicholas --- docs/releases.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/releases.rst b/docs/releases.rst index 0fc63dab..8bbd1089 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -13,7 +13,7 @@ Breaking changes ~~~~~~~~~~~~~~~~ - Requires Zarr 3.0 (for :pull:`182`). - By `Tom Nicholas `_. + By `Gustavo Hidalgo `_. Deprecations ~~~~~~~~~~~~ From 8c2a7a0da1ce5125029331f7fab2662323424749 Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Wed, 10 Jul 2024 14:21:54 -0400 Subject: [PATCH 4/5] unvendor json_dumps --- virtualizarr/vendor/zarr/LICENSE.txt | 21 --------------------- virtualizarr/vendor/zarr/__init__.py | 0 virtualizarr/vendor/zarr/utils.py | 26 -------------------------- virtualizarr/zarr.py | 3 +-- 4 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 virtualizarr/vendor/zarr/LICENSE.txt delete mode 100644 virtualizarr/vendor/zarr/__init__.py delete mode 100644 virtualizarr/vendor/zarr/utils.py diff --git a/virtualizarr/vendor/zarr/LICENSE.txt b/virtualizarr/vendor/zarr/LICENSE.txt deleted file mode 100644 index a4de1c39..00000000 --- a/virtualizarr/vendor/zarr/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015-2024 Zarr Developers - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/virtualizarr/vendor/zarr/__init__.py b/virtualizarr/vendor/zarr/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/virtualizarr/vendor/zarr/utils.py b/virtualizarr/vendor/zarr/utils.py deleted file mode 100644 index 32986793..00000000 --- a/virtualizarr/vendor/zarr/utils.py +++ /dev/null @@ -1,26 +0,0 @@ -import json -import numbers -from typing import Any - - -class NumberEncoder(json.JSONEncoder): - def default(self, o): - # See json.JSONEncoder.default docstring for explanation - # This is necessary to encode numpy dtype - if isinstance(o, numbers.Integral): - return int(o) - if isinstance(o, numbers.Real): - return float(o) - return json.JSONEncoder.default(self, o) - - -def json_dumps(o: Any) -> bytes: - """Write JSON in a consistent, human-readable way.""" - return json.dumps( - o, - indent=4, - sort_keys=True, - ensure_ascii=True, - separators=(",", ": "), - cls=NumberEncoder, - ).encode("ascii") diff --git a/virtualizarr/zarr.py b/virtualizarr/zarr.py index 545a86fc..f2f15bcb 100644 --- a/virtualizarr/zarr.py +++ b/virtualizarr/zarr.py @@ -12,8 +12,7 @@ import ujson # type: ignore import xarray as xr from pydantic import BaseModel, ConfigDict, field_validator - -from virtualizarr.vendor.zarr.utils import json_dumps +from zarr.v2.util import json_dumps if TYPE_CHECKING: pass From 933e575ce53adbab81516b4ba3d7942e7103d082 Mon Sep 17 00:00:00 2001 From: Gustavo Hidalgo Date: Thu, 11 Jul 2024 10:29:59 -0400 Subject: [PATCH 5/5] Revert "unvendor json_dumps" This reverts commit 8c2a7a0da1ce5125029331f7fab2662323424749. --- virtualizarr/vendor/zarr/LICENSE.txt | 21 +++++++++++++++++++++ virtualizarr/vendor/zarr/__init__.py | 0 virtualizarr/vendor/zarr/utils.py | 26 ++++++++++++++++++++++++++ virtualizarr/zarr.py | 3 ++- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 virtualizarr/vendor/zarr/LICENSE.txt create mode 100644 virtualizarr/vendor/zarr/__init__.py create mode 100644 virtualizarr/vendor/zarr/utils.py diff --git a/virtualizarr/vendor/zarr/LICENSE.txt b/virtualizarr/vendor/zarr/LICENSE.txt new file mode 100644 index 00000000..a4de1c39 --- /dev/null +++ b/virtualizarr/vendor/zarr/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2024 Zarr Developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/virtualizarr/vendor/zarr/__init__.py b/virtualizarr/vendor/zarr/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/virtualizarr/vendor/zarr/utils.py b/virtualizarr/vendor/zarr/utils.py new file mode 100644 index 00000000..32986793 --- /dev/null +++ b/virtualizarr/vendor/zarr/utils.py @@ -0,0 +1,26 @@ +import json +import numbers +from typing import Any + + +class NumberEncoder(json.JSONEncoder): + def default(self, o): + # See json.JSONEncoder.default docstring for explanation + # This is necessary to encode numpy dtype + if isinstance(o, numbers.Integral): + return int(o) + if isinstance(o, numbers.Real): + return float(o) + return json.JSONEncoder.default(self, o) + + +def json_dumps(o: Any) -> bytes: + """Write JSON in a consistent, human-readable way.""" + return json.dumps( + o, + indent=4, + sort_keys=True, + ensure_ascii=True, + separators=(",", ": "), + cls=NumberEncoder, + ).encode("ascii") diff --git a/virtualizarr/zarr.py b/virtualizarr/zarr.py index f2f15bcb..545a86fc 100644 --- a/virtualizarr/zarr.py +++ b/virtualizarr/zarr.py @@ -12,7 +12,8 @@ import ujson # type: ignore import xarray as xr from pydantic import BaseModel, ConfigDict, field_validator -from zarr.v2.util import json_dumps + +from virtualizarr.vendor.zarr.utils import json_dumps if TYPE_CHECKING: pass