-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: follow-ups to recent PRs #38840
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1274,22 +1274,6 @@ def shift(self, periods: int, axis: int = 0, fill_value=None): | |
|
||
return [self.make_block(new_values)] | ||
|
||
def _maybe_reshape_where_args(self, values, other, cond, axis): | ||
transpose = self.ndim == 2 | ||
|
||
cond = _extract_bool_array(cond) | ||
|
||
# If the default broadcasting would go in the wrong direction, then | ||
# explicitly reshape other instead | ||
if getattr(other, "ndim", 0) >= 1: | ||
if values.ndim - 1 == other.ndim and axis == 1: | ||
other = other.reshape(tuple(other.shape + (1,))) | ||
elif transpose and values.ndim == self.ndim - 1: | ||
# TODO(EA2D): not neceesssary with 2D EAs | ||
cond = cond.T | ||
|
||
return other, cond | ||
|
||
def where(self, other, cond, errors="raise", axis: int = 0) -> List["Block"]: | ||
""" | ||
evaluate the block; return result block(s) from the result | ||
|
@@ -1319,7 +1303,7 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List["Block"]: | |
if transpose: | ||
values = values.T | ||
|
||
other, cond = self._maybe_reshape_where_args(values, other, cond, axis) | ||
cond = _extract_bool_array(cond) | ||
|
||
if cond.ravel("K").all(): | ||
result = values | ||
|
@@ -2072,7 +2056,7 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List["Block"]: | |
# TODO(EA2D): reshape unnecessary with 2D EAs | ||
arr = self.array_values().reshape(self.shape) | ||
|
||
other, cond = self._maybe_reshape_where_args(arr, other, cond, axis) | ||
cond = _extract_bool_array(cond) | ||
|
||
try: | ||
res_values = arr.T.where(cond, other).T | ||
|
@@ -2572,23 +2556,20 @@ def _block_shape(values: ArrayLike, ndim: int = 1) -> ArrayLike: | |
return values | ||
|
||
|
||
def safe_reshape(arr, new_shape: Shape): | ||
def safe_reshape(arr: ArrayLike, new_shape: Shape) -> ArrayLike: | ||
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. The docstring implies that Series and Index are allowed 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. updated the docstring |
||
""" | ||
If possible, reshape `arr` to have shape `new_shape`, | ||
with a couple of exceptions (see gh-13012): | ||
|
||
1) If `arr` is a ExtensionArray or Index, `arr` will be | ||
returned as is. | ||
2) If `arr` is a Series, the `_values` attribute will | ||
be reshaped and returned. | ||
Reshape `arr` to have shape `new_shape`, unless it is an ExtensionArray, | ||
in which case it will be returned unchanged (see gh-13012). | ||
|
||
Parameters | ||
---------- | ||
arr : array-like, object to be reshaped | ||
new_shape : int or tuple of ints, the new shape | ||
arr : np.ndarray or ExtensionArray | ||
new_shape : Tuple[int] | ||
|
||
Returns | ||
------- | ||
np.ndarray or ExtensionArray | ||
""" | ||
if isinstance(arr, ABCSeries): | ||
arr = arr._values | ||
if not is_extension_array_dtype(arr.dtype): | ||
# Note: this will include TimedeltaArray and tz-naive DatetimeArray | ||
# TODO(EA2D): special case will be unnecessary with 2D EAs | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
wow!