-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: do ndim validation before Block.__init__ #40337
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
PERF: do ndim validation before Block.__init__ #40337
Conversation
pandas/core/internals/blocks.py
Outdated
raise AssertionError("block.size != values.size") | ||
|
||
|
||
def extract_pandas_array(values, dtype, ndim): |
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.
ideally type & full docstring, shouldn't this live with extract_array?
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.
ideally type & full docstring
sure
shouldn't this live with extract_array?
short answer: not sure yet. i need to untangle the patching we do in test_numpy (xref #40021)
pandas/core/internals/managers.py
Outdated
@@ -1610,6 +1610,8 @@ def get_slice(self, slobj: slice, axis: int = 0) -> SingleBlockManager: | |||
|
|||
blk = self._block | |||
array = blk._slice(slobj) | |||
if array.ndim > blk.values.ndim: | |||
raise ValueError |
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.
message?
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.
could add something in to be on the safe side, but this is only reached when called from Series.get_value, where it is caught and handled
Updated with exception message, docstring, annotations |
) | ||
assert result.dtype.kind in ["i", "u"] | ||
assert result.is_extension is False | ||
if block_maker is make_block: |
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.
i guess could have the else path here as well to assert the public api?
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 the pseudo-public api
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.
right what i mean is what's the else path? (an internal path)?
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.
correct. the internal path no longer takes the dtype kwd checked below
anything else here? several perf-improving follow-ups as we get validation out of the constructors |
No description provided.