-
Notifications
You must be signed in to change notification settings - Fork 89
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
refactor: replace simplify_optiontype
and simplify_uniontype
with simplified
classmethod
#1928
refactor: replace simplify_optiontype
and simplify_uniontype
with simplified
classmethod
#1928
Conversation
…method-constructor
simplify_optiontype
and simplify_uniontype
with simplified
classmethodsimplify_optiontype
and simplify_uniontype
with simplified
classmethod
Codecov Report
Additional details and impacted files
|
…ey're right after the normal constructor, now.
next = item.simplify_optiontype() | ||
return normalise_item_nested(next) | ||
return normalise_item_nested(item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the few that doesn't replace a simplify_optiontype
with a simplified
classmethod—not a pure refactor—so it's possible that non-canonical layouts pass through here.
However, I think this was sanitizing user input, and after constructors forbid non-canonical structures, user input can't be insane. So while this opens the door to error, the next PR will shut it.
return [self.simplify_optiontype()] | ||
return [self] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's another unbalanced simplify_optiontype
→ simplified
pair, but in the future, self
can't be non-canonical.
return [self.simplify_optiontype()] | ||
return [self] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unbalanced simplify_optiontype
→ simplified
pair.
return [self.simplify_optiontype()] | ||
return [self] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unbalanced simplify_optiontype
→ simplified
pair.
return [self.simplify_optiontype()] | ||
return [self] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unbalanced simplify_optiontype
→ simplified
pair.
return continuation().simplify_optiontype() | ||
return continuation() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unbalanced simplify_optiontype
→ simplified
pair.
if layout.is_option: | ||
layout = layout.simplify_optiontype() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last unbalanced simplify_optiontype
→ simplified
pair.
@agoose77 The PyLint test is failing because |
@jpivarski |
This commit enables backends to pass through `regularize_backend`, and ensures that we pass a backend (not nplike) to `from_buffers`
I took your comment as a green light to push some fixes. Feel free to revert / rebase them if you're not happy. |
attempt = item.simplify_uniontype() | ||
if isinstance(attempt, ak.contents.UnionArray): | ||
raise ak._errors.wrap_error( | ||
TypeError( | ||
"irreducible unions (different types at the same level in an array) can't be used as slices" | ||
) | ||
raise ak._errors.wrap_error( | ||
TypeError( | ||
"irreducible unions (different types at the same level in an array) can't be used as slices" | ||
) | ||
|
||
return normalise_item_nested(attempt) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not a simplify_uniontype
→ simplified
pair because it's sanitizing input, just in case (like the option-type exceptions noted above).
src/awkward/contents/unionarray.py
Outdated
for i, self_cont in enumerate(contents): | ||
for i, self_cont in enumerate(self_contents): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This had been an error in the translation of simplify_uniontype
to simplified
. I don't see any similar errors.
def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, tail): | ||
simplified = self.simplify_uniontype() | ||
if isinstance(simplified, ak.contents.UnionArray): | ||
if isinstance(self, ak.contents.UnionArray): | ||
raise ak._errors.index_error( | ||
self, | ||
ak.contents.ListArray( | ||
slicestarts, slicestops, slicecontent, parameters=None | ||
), | ||
"cannot apply jagged slices to irreducible union arrays", | ||
) | ||
return simplified._getitem_next_jagged( | ||
slicestarts, slicestops, slicecontent, tail | ||
) | ||
return self._getitem_next_jagged(slicestarts, slicestops, slicecontent, tail) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not a simplify_uniontype
→ simplified
pair because it's sanitizing input. There was a test providing insane inputs, so the simplified
part of the pair went into the testing code.
simplified = self.simplify_uniontype(True, True) | ||
simplified = type(self).simplified( | ||
self._tags, | ||
self._index, | ||
self._contents, | ||
parameters=self._parameters, | ||
backend=self._backend, | ||
merge=True, | ||
mergebool=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one re-simplifies the inputs because the merging strategy is more aggressive than normal (mergebool=True
), so this is to prevent any changes in behavior.
simplified = self.simplify_uniontype(True, True) | ||
simplified = type(self).simplified( | ||
self._tags, | ||
self._index, | ||
self._contents, | ||
parameters=self._parameters, | ||
backend=self._backend, | ||
merge=True, | ||
mergebool=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
simplified = self.simplify_uniontype(mergebool=True) | ||
simplified = type(self).simplified( | ||
self._tags, | ||
self._index, | ||
self._contents, | ||
parameters=self._parameters, | ||
backend=self._backend, | ||
mergebool=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
simplified = self.simplify_uniontype(mergebool=True) | ||
simplified = type(self).simplified( | ||
self._tags, | ||
self._index, | ||
self._contents, | ||
parameters=self._parameters, | ||
backend=self._backend, | ||
mergebool=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
simplified = self.simplify_uniontype(mergebool=True) | ||
simplified = type(self).simplified( | ||
self._tags, | ||
self._index, | ||
self._contents, | ||
parameters=self._parameters, | ||
backend=self._backend, | ||
mergebool=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
out = out.simplify_uniontype(merge=merge, mergebool=mergebool) | ||
out = type(out).simplified( | ||
out._tags, | ||
out._index, | ||
out._contents, | ||
parameters=out._parameters, | ||
backend=out._backend, | ||
merge=merge, | ||
mergebool=mergebool, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above (mergebool
might be True
).
…method-constructor
@agoose77, this is now fully implemented and ready for review. Each step is called out in code comments, and the last step is this: the
into
That is, Arrow convention is now forced. The way that option-type push-down is implemented (there are many choices!) is this: one of the UnionArray contents, We can change the way What this PR does not implement is the canonicity requirements in the Content constructors. That's why #1910 is not closed by this PR. But now that we have a constructor that makes canonical versions of any Content, the next PR just has to enforce those requirements, discover if we are using non-canonical constructions anywhere, and build them with |
Co-authored-by: Angus Hollands <[email protected]>
Co-authored-by: Angus Hollands <[email protected]>
Co-authored-by: Angus Hollands <[email protected]>
Co-authored-by: Angus Hollands <[email protected]>
Co-authored-by: Angus Hollands <[email protected]>
Instead of constructing non-canonical arrays and then simplifying them into something canonical, these
@classmethods
only construct canonical arrays from the start.The next PR after this will enforce canonicity (level 1) in the Content constructors. This is the first half of #1910.
📚 The documentation for this PR will be available at https://awkward-array.readthedocs.io/en/jpivarski-replace-simplify-method-with-classmethod-constructor/ once Read the Docs has finished building 🔨