Skip to content

Commit

Permalink
Revert "unvendor json_dumps"
Browse files Browse the repository at this point in the history
This reverts commit 8c2a7a0.
  • Loading branch information
ghidalgo3 committed Jul 11, 2024
1 parent 8c2a7a0 commit 933e575
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
21 changes: 21 additions & 0 deletions virtualizarr/vendor/zarr/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-2024 Zarr Developers <https://github.com/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.
Empty file.
26 changes: 26 additions & 0 deletions virtualizarr/vendor/zarr/utils.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion virtualizarr/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 933e575

Please sign in to comment.