-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 |
||
block = blk.make_block_same_class(array, placement=slice(0, len(array))) | ||
return type(self)(block, self.index[slobj]) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1318,17 +1318,19 @@ def test_make_block_no_pandas_array(block_maker): | |
assert result.dtype.kind in ["i", "u"] | ||
assert result.is_extension is False | ||
|
||
# PandasArray, PandasDtype | ||
result = block_maker(arr, slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim) | ||
assert result.dtype.kind in ["i", "u"] | ||
assert result.is_extension is False | ||
|
||
# ndarray, PandasDtype | ||
result = block_maker( | ||
arr.to_numpy(), slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim | ||
) | ||
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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. correct. the internal path no longer takes the dtype kwd checked below |
||
# PandasArray, PandasDtype | ||
result = block_maker(arr, slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim) | ||
assert result.dtype.kind in ["i", "u"] | ||
assert result.is_extension is False | ||
|
||
# new_block no longer taked dtype keyword | ||
# ndarray, PandasDtype | ||
result = block_maker( | ||
arr.to_numpy(), slice(len(arr)), dtype=arr.dtype, ndim=arr.ndim | ||
) | ||
assert result.dtype.kind in ["i", "u"] | ||
assert result.is_extension is False | ||
|
||
|
||
def test_single_block_manager_fastpath_deprecated(): | ||
|
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.
sure
short answer: not sure yet. i need to untangle the patching we do in test_numpy (xref #40021)