From 9e10980d1e8102dfa3291ebac91396fb179cd559 Mon Sep 17 00:00:00 2001 From: Ryan Grout Date: Tue, 20 Jan 2026 15:23:05 -0700 Subject: [PATCH 1/5] Squeeze fill value. --- kerchunk/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kerchunk/utils.py b/kerchunk/utils.py index f0289f86..56e31016 100644 --- a/kerchunk/utils.py +++ b/kerchunk/utils.py @@ -217,6 +217,8 @@ def encode_fill_value(v: Any, dtype: np.dtype, compressor: Any = None) -> Any: # early out if v is None: return v + v = np.asanyarray(v, dtype=dtype) + v = v.squeeze() if dtype.kind == "V" and dtype.hasobject: if compressor is None: raise ValueError("missing compressor for object array") From c8927673df848f841e79c4848612aa2e88cf6039 Mon Sep 17 00:00:00 2001 From: Ryan Grout Date: Tue, 20 Jan 2026 16:14:03 -0700 Subject: [PATCH 2/5] Add commentary. --- kerchunk/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kerchunk/utils.py b/kerchunk/utils.py index 56e31016..1306ffcd 100644 --- a/kerchunk/utils.py +++ b/kerchunk/utils.py @@ -217,8 +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") From a51ef3a5cb169185dc03a2dd1dd876ddfa59c2eb Mon Sep 17 00:00:00 2001 From: Ryan Grout Date: Tue, 20 Jan 2026 16:37:52 -0700 Subject: [PATCH 3/5] Add basic tests. --- tests/test_utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index f6c7e5ef..d6110538 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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 From c784644d1e381192a69dee2eb63302a30f65951c Mon Sep 17 00:00:00 2001 From: Ryan Grout Date: Wed, 21 Jan 2026 09:54:40 -0700 Subject: [PATCH 4/5] Fix linting issues. --- tests/test_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index d6110538..5b686a67 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -179,7 +179,7 @@ def test_deflate_zip_archive(m): 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 + 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 From 0878c721f394560225bebde7f3a9343cca9cc195 Mon Sep 17 00:00:00 2001 From: Ryan Grout Date: Wed, 21 Jan 2026 09:58:25 -0700 Subject: [PATCH 5/5] More linting. --- kerchunk/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kerchunk/utils.py b/kerchunk/utils.py index 1306ffcd..7d9dae6a 100644 --- a/kerchunk/utils.py +++ b/kerchunk/utils.py @@ -217,14 +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")