-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
[BUG] maybe_upcast_putmast also handle ndarray #25431
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25431 +/- ##
==========================================
+ Coverage 91.74% 91.77% +0.03%
==========================================
Files 173 173
Lines 52923 52925 +2
==========================================
+ Hits 48554 48572 +18
+ Misses 4369 4353 -16
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25431 +/- ##
==========================================
+ Coverage 91.27% 91.3% +0.03%
==========================================
Files 173 173
Lines 53002 53004 +2
==========================================
+ Hits 48375 48396 +21
+ Misses 4627 4608 -19
Continue to review full report at Codecov.
|
expected = np.array([10, 61, 12]) | ||
|
||
result, _ = maybe_upcast_putmask(result, mask, other) | ||
tm.assert_numpy_array_equal(result, expected) |
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 suspect these tests already have a home in another, existing test file.
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.
Also, reference the issue number as a comment under each test definition.
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.
what problem is this solving?
from pandas.util import testing as tm | ||
|
||
|
||
def test_upcast_series(): |
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.
can you parameterize these (both tests) as I suspect a myriad of cases (just a couple for now, e.g. int -> float you can start with)
pandas/core/dtypes/cast.py
Outdated
new_result = result.values.copy() | ||
if isinstance(result, np.ndarray): | ||
new_result = result.copy() | ||
else: |
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.
what other types are here? a Series?
this should be converted at a higher level (at the beginning of the function)
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -105,7 +105,7 @@ Performance Improvements | |||
Bug Fixes | |||
~~~~~~~~~ | |||
|
|||
- | |||
- :func:`maybe_upcast_putmask` does not replace the element of the ``ndarray`` correctly (:issue:`23823`) |
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 doesn't warrant a whatsnew as its an internal impl detail
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.
can you remove
I investigated further and found that I misunderstood the usage of The result array should be replaced with the element of other array starting from the beginning, not in the position of mask. This behavior is due to np.place
So the behavior for Series as an input is not correct. And
Examples can be added into the function docstring to elucidate the usage. Should I do it in this PR? |
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.
can you update with your new tests. also you can do an assert on the input of the function itself (e.g. assert its an ndarray)
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -105,7 +105,7 @@ Performance Improvements | |||
Bug Fixes | |||
~~~~~~~~~ | |||
|
|||
- | |||
- :func:`maybe_upcast_putmask` does not replace the element of the ``ndarray`` correctly (:issue:`23823`) |
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.
can you remove
bf23643
to
5e09d2d
Compare
When adding the tests, the following bug is found and fixed.
|
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.
minor comments, merge master, ping on green.
from pandas.util import testing as tm | ||
|
||
|
||
def test_upcast_error(): |
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.
are there more cases to consider? e.g. non-ndarray
thanks @makbigc keep em coming! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Follow h-vetinari's footstep.
maybe_upcast_putmask
was left untouched in #25425. Try to fix the bug so thatmaybe_upcast_putmask
can also handlendarray
as well asSeries
.