Skip to content

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

Merged
merged 3 commits into from
Mar 10, 2021

Conversation

jbrockmendel
Copy link
Member

No description provided.

raise AssertionError("block.size != values.size")


def extract_pandas_array(values, dtype, ndim):
Copy link
Contributor

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?

Copy link
Member Author

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)

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message?

Copy link
Member Author

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

@jreback jreback added the Internals Related to non-user accessible pandas implementation label Mar 9, 2021
@jbrockmendel
Copy link
Member Author

Updated with exception message, docstring, annotations

@jreback jreback added this to the 1.3 milestone Mar 10, 2021
)
assert result.dtype.kind in ["i", "u"]
assert result.is_extension is False
if block_maker is make_block:
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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)?

Copy link
Member Author

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

@jbrockmendel
Copy link
Member Author

anything else here? several perf-improving follow-ups as we get validation out of the constructors

@jreback jreback merged commit 1f5e358 into pandas-dev:master Mar 10, 2021
@jbrockmendel jbrockmendel deleted the perf-validate-earlier branch March 10, 2021 22:30
jbrockmendel added a commit to jbrockmendel/pandas that referenced this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants