-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix nanmedian for CoW without bottleneck #55742
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
3 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
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.
I think that in theory, this copy might not be needed, and we could also ignore the read-only flag instead. The case that could still end up here is the masked Float64Dtype, where you do pass float64 data together with a mask. Although in that case, setting the values under the mask to NaN should I think always be "safe" at the moment (I don't think we already allow sharing data but not mask between FloatingArrays). But that's maybe something we can optimize later for Float64Dtype when we have a better idea of its memory model (and if sharing of data is definitely never possible)
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.
Now, looking a bit more, in practice we don't actually get here for FloatingArray at the moment, for two reasons:
we don't yet mark the numpy arrays as read-only when accessing those (FloatingArray
_data
), so it's only for the numpy float64 dtype that we would get read-only data at the momentif there are missing values in the FloatArray, we actually already copy the values inside
_get_values
:pandas/pandas/core/nanops.py
Lines 312 to 316 in 984d755
Now, that seems double effort, and something we should fix, but that's for another issue (we are also setting with a fill_value of 0 here, which doesn't seem to make sense in the case of
median
, and then in nanmedian itself we either filter with the mask or set NaNs into it ..)So I can also leave out this
if not values.flags.writeable:
check, because right now it will not be covered by any test / case in pandas, I think (unless you would use nanmedian directly)