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
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ skops Changelog

v0.17
-----
- Fix loading empty NumPy object arrays: the recorded shape is preserved even
when a zero-length axis hides later dimensions from the nested list.
- Fix ``skops update`` failing when a relative output path contains a
directory, including updates with ``--inplace``.
- Loading a skops file now checks that each part of the file holds the kind
Expand Down
3 changes: 3 additions & 0 deletions skops/io/_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def _construct(self):
shape = self.shape.construct()
tmp = [o.construct() for o in self.items]

if 0 in shape:
return np.empty(shape, dtype="O")

# TODO: this is a hack to get the correct shape of the array. We
# should find _a better way_ to do this.
if len(shape) == 1:
Expand Down
19 changes: 19 additions & 0 deletions skops/io/tests/test_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,25 @@ def test_numpy_object_dtype_2d_array(transpose):
assert_params_equal(est.__dict__, loaded.__dict__)


@pytest.mark.parametrize(
"shape", [(0,), (0, 3), (2, 0), (2, 0, 3), (2, 3, 0), (0, 2, 3), (2, 3)]
)
@pytest.mark.parametrize("use_file", [False, True])
def test_numpy_object_dtype_empty_array(shape, use_file, tmp_path):
arr = np.full(shape, "value", dtype=object)

if use_file:
path = tmp_path / "array.skops"
dump(arr, path)
loaded = load(path)
else:
loaded = loads(dumps(arr))

assert loaded.shape == shape
assert loaded.dtype == arr.dtype
np.testing.assert_array_equal(loaded, arr)


def test_metainfo():
class MyEstimator(BaseEstimator):
"""Estimator with attributes of different supported types"""
Expand Down
Loading