Skip to content

Commit a90a6a9

Browse files
authored
refactor: remove Array shape default (#2026)
We get the `TypeError` for free: ```py import narwhals as nw >>> nw.Array(nw.Int64) TypeError: Array.__init__() missing 1 required positional argument: 'shape' ```
1 parent 43d072b commit a90a6a9

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

narwhals/dtypes.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,9 @@ class Array(NestedType):
790790
shape: tuple[int, ...]
791791

792792
def __init__(
793-
self: Self,
794-
inner: DType | type[DType],
795-
shape: int | tuple[int, ...] | None = None,
793+
self: Self, inner: DType | type[DType], shape: int | tuple[int, ...]
796794
) -> None:
797795
inner_shape: tuple[int, ...] = inner.shape if isinstance(inner, Array) else ()
798-
799-
if shape is None: # pragma: no cover
800-
msg = "Array constructor is missing the required argument `shape`"
801-
raise TypeError(msg)
802-
803796
if isinstance(shape, int):
804797
self.inner = inner
805798
self.size = shape

tests/dtypes_test.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ def test_array_valid() -> None:
8787
assert dtype != nw.Array(nw.Array(nw.Float32, 2), 2)
8888
assert dtype in {nw.Array(nw.Array(nw.Int64, 2), 2)}
8989

90-
with pytest.raises(
91-
TypeError, match="Array constructor is missing the required argument `shape`"
92-
):
93-
nw.Array(nw.Int64)
90+
with pytest.raises(TypeError, match="invalid input for shape"):
91+
nw.Array(nw.Int64(), shape=None) # type: ignore[arg-type]
9492

9593
with pytest.raises(TypeError, match="invalid input for shape"):
9694
nw.Array(nw.Int64(), shape="invalid_type") # type: ignore[arg-type]

0 commit comments

Comments
 (0)