Skip to content

Commit

Permalink
fix: requesting layout.form should not touch shape (#3189)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski authored Jul 31, 2024
1 parent d5bc304 commit 39541db
Show file tree
Hide file tree
Showing 3 changed files with 967 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/awkward/_nplikes/typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ def shape(self) -> tuple[ShapeItem, ...]:
self.touch_shape()
return self._shape

@property
def inner_shape(self) -> tuple[ShapeItem, ...]:
if len(self._shape) > 1:
self.touch_shape()
return self._shape[1:]

@property
def form_key(self) -> str | None:
return self._form_key
Expand Down Expand Up @@ -1332,8 +1338,8 @@ def concat(self, arrays, *, axis: int | None = 0) -> TypeTracerArray:
for x in arrays:
assert isinstance(x, TypeTracerArray)
if inner_shape is None:
inner_shape = x.shape[1:]
elif inner_shape != x.shape[1:]:
inner_shape = x.inner_shape
elif inner_shape != x.inner_shape:
raise ValueError(
f"inner dimensions don't match in concatenate: {inner_shape} vs {x.shape[1:]}"
)
Expand Down
7 changes: 6 additions & 1 deletion src/awkward/contents/numpyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ def _raw(self, nplike=None):
return to_nplike(self.data, nplike, from_nplike=self._backend.nplike)

def _form_with_key(self, getkey: Callable[[Content], str | None]) -> NumpyForm:
if hasattr(self._data, "inner_shape"):
inner_shape = self._data.inner_shape
else:
inner_shape = self._data.shape[1:]

return self.form_cls(
ak.types.numpytype.dtype_to_primitive(self._data.dtype),
self._data.shape[1:],
inner_shape,
parameters=self._parameters,
form_key=getkey(self),
)
Expand Down
Loading

0 comments on commit 39541db

Please sign in to comment.