Skip to content

Commit

Permalink
FIX: use None as the sentinel for the units kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
genematx committed Sep 11, 2024
1 parent 484c6a0 commit c9fa03e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tiled/server/pydantic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BuiltinDtype(BaseModel):
endianness: Endianness
kind: Kind
itemsize: int
units: str = ""
units: Optional[str] = None

__endianness_map = {
">": "big",
Expand All @@ -43,7 +43,7 @@ class BuiltinDtype(BaseModel):
def from_numpy_dtype(cls, dtype) -> "BuiltinDtype":
# Extract datetime units from the dtype string representation,
# e.g. `'<M8[ns]'` has `units = 'ns'`.
units = ""
units = None
if dtype.kind in ("m", "M"):
if res := re.search(r"\[(.+)\]$", dtype.str):
units = res.group(1)
Expand Down Expand Up @@ -79,7 +79,7 @@ def from_json(cls, structure):
kind=Kind(structure["kind"]),
itemsize=structure["itemsize"],
endianness=Endianness(structure["endianness"]),
units=structure.get("units", ""),
units=structure.get("units"),
)


Expand Down
6 changes: 3 additions & 3 deletions tiled/structures/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BuiltinDtype:
endianness: Endianness
kind: Kind
itemsize: int
units: str = ""
units: Optional[str] = None

__endianness_map = {
">": "big",
Expand All @@ -92,7 +92,7 @@ class BuiltinDtype:
def from_numpy_dtype(cls, dtype) -> "BuiltinDtype":
# Extract datetime units from the dtype string representation,
# e.g. `'<M8[ns]'` has `units = 'ns'`.
units = ""
units = None
if dtype.kind in ("m", "M"):
if res := re.search(r"\[(.+)\]$", dtype.str):
units = res.group(1)
Expand Down Expand Up @@ -128,7 +128,7 @@ def from_json(cls, structure):
kind=Kind(structure["kind"]),
itemsize=structure["itemsize"],
endianness=Endianness(structure["endianness"]),
units=structure.get("units", ""),
units=structure.get("units"),
)


Expand Down

0 comments on commit c9fa03e

Please sign in to comment.