Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: requesting layout.form should not touch shape #3189

Merged
merged 2 commits into from
Jul 31, 2024
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
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
Loading