Skip to content

Commit

Permalink
Initialize ndim value for Points layer using data shape if available (n…
Browse files Browse the repository at this point in the history
…apari#6593)

# References and relevant issues

Closes napari#6587 

# Description

Add handling for layer dimensionality initialization by using passed
data shape value if available to set `ndim` when kwarg is not passed
  • Loading branch information
dalthviz authored Jan 22, 2024
1 parent 1ee3a39 commit 565f659
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions napari/layers/points/_tests/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def _make_cycled_properties(values, length):
def test_empty_points():
pts = Points()
assert pts.data.shape == (0, 2)
assert pts.ndim == 2


def test_3d_empty_points():
pts = Points(np.empty((0, 3)))
assert pts.ndim == 3


def test_empty_points_with_features():
Expand Down
11 changes: 9 additions & 2 deletions napari/layers/points/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,15 @@ def __init__(
shown=True,
projection_mode='none',
) -> None:
if ndim is None and scale is not None:
ndim = len(scale)
if ndim is None:
if scale is not None:
ndim = len(scale)
elif (
data is not None
and hasattr(data, 'shape')
and len(data.shape) == 2
):
ndim = data.shape[1]

data, ndim = fix_data_points(data, ndim)

Expand Down

0 comments on commit 565f659

Please sign in to comment.