Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions kerchunk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def encode_fill_value(v: Any, dtype: np.dtype, compressor: Any = None) -> Any:
# early out
if v is None:
return v

# Assure that v is a numpy array of the appropriate dtype
v = np.asanyarray(v, dtype=dtype)
# If v is 1D and only has 1 element, squeeze it to 0-D ndarray.
# When v is not 0-D, calling int/float/bool on v will fail
# We still need an ndarray in case dtype is a date
v = v.squeeze()

if dtype.kind == "V" and dtype.hasobject:
if compressor is None:
raise ValueError("missing compressor for object array")
Expand Down
7 changes: 7 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,10 @@ def test_deflate_zip_archive(m):

fs = fsspec.filesystem("reference", fo=refs2)
assert dec.decode(fs.cat("b")) == data


def test_encode_fill_value():
assert kerchunk.utils.encode_fill_value(np.array([9999]), np.dtype("int")) == 9999
assert kerchunk.utils.encode_fill_value(np.array(9999), np.dtype("int")) == 9999
assert kerchunk.utils.encode_fill_value([9999], np.dtype("int")) == 9999
assert kerchunk.utils.encode_fill_value(9999, np.dtype("int")) == 9999
Loading