-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Change UInt64Index._na_value from 0 to np.nan #18401
Conversation
pandas/tests/indexes/test_base.py
Outdated
|
||
# fall back to Float64Index | ||
data = [0.0, 1.1, 2.2, 3.3] | ||
expected = Float64Index(data) |
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.
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.
these should raise as they are passing a dtype that is non convertible
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.
Removed the Float64Index
portion of the test. Was able to get it to raise, but ended up breaking other things. Not immediately sure of the fix, but seems outside the scope of this PR, though can look into it more if need be. None of the code I wrote actually depends on that behavior; originally included it to make sure all code paths were tested.
Codecov Report
@@ Coverage Diff @@
## master #18401 +/- ##
==========================================
- Coverage 91.36% 91.34% -0.02%
==========================================
Files 164 164
Lines 49730 49730
==========================================
- Hits 45435 45426 -9
- Misses 4295 4304 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18401 +/- ##
==========================================
- Coverage 91.35% 91.31% -0.05%
==========================================
Files 163 163
Lines 49695 49695
==========================================
- Hits 45401 45380 -21
- Misses 4294 4315 +21
Continue to review full report at Codecov.
|
return Int64Index(res, copy=copy, name=name) | ||
except (OverflowError, TypeError, ValueError): | ||
pass | ||
if not is_unsigned_integer_dtype(dtype): |
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 add a comment here (eg. about why we don't convert for uint)
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.
done
pandas/tests/indexes/test_numeric.py
Outdated
klasses = [list, tuple, np.array, pd.Series] | ||
expected = Float64Index([_nan] + i[1:].tolist()) | ||
|
||
for klass in klasses: |
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.
you could parametrize
@@ -108,7 +108,7 @@ Bug Fixes | |||
Conversion | |||
^^^^^^^^^^ | |||
|
|||
- | |||
- Bug in :class:`Index` constructor with `dtype='uint64'` where int-like floats were not coerced to :class:`UInt64Index` (:issue:`18400`) |
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.
18398 as well?
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.
Added a separate entry for 18398 under "Backwards incompatible API changes"
ea978b0
to
619341b
Compare
Regarding the
|
619341b
to
92c5442
Compare
can you rebase. ready to go? |
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -36,7 +36,7 @@ Backwards incompatible API changes | |||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |||
|
|||
- :func:`Series.fillna` now raises a ``TypeError`` instead of a ``ValueError`` when passed a list, tuple or DataFrame as a ``value`` (:issue:`18293`) | |||
- | |||
- The default NA value for :class:`UInt64Index` has changed from 0 to ``NaN`` (:issue:`18398`) |
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 user visible change has this?
Now it sounds a bit vague
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.
It impacts things that mask with NA under the hood, such as .where
Previous behavior:
In [3]: idx = pd.UInt64Index(range(5))
In [4]: idx
Out[4]: UInt64Index([0, 1, 2, 3, 4], dtype='uint64')
In [5]: idx.where(idx > 3)
Out[5]: UInt64Index([0, 0, 0, 0, 4], dtype='uint64')
New behavior:
In [3]: idx = pd.UInt64Index(range(5))
In [4]: idx.where(idx > 3)
Out[4]: Float64Index([nan, nan, nan, nan, 4.0], dtype='float64')
Updating the whatsnew to make this more clear.
92c5442
to
48d1f6f
Compare
48d1f6f
to
0852ecb
Compare
@jreback : this should be ready to merge once green, assuming that the whatsnew change I made to address the comment by @jorisvandenbossche is acceptable. |
@@ -269,28 +269,19 @@ def f(x): | |||
ordered=False) | |||
tm.assert_index_equal(result, exp) | |||
|
|||
def test_where(self): | |||
@pytest.mark.parametrize('klass', [list, tuple, np.array, pd.Series]) | |||
def test_where(self, klass): |
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.
we should prob move all of the test_where tests to test_base and use the indices fixture to avoid the code repetition (new issue though)
thanks @jschendel very nice! |
Prerequisite for #18300
git diff upstream/master -u -- "*.py" | flake8 --diff
Summary:
Changed
UInt64Index._na_value
from 0 tonp.nan
Added a
dtype
parameter to_try_convert_to_int_index
to skip the initial attempt to coerce toInt64Index
in cases where we really wantUInt64Index
(fix for BUG: Index constructor doesn't coerce int-like floats to UInt64Index #18400).Moved
test_where
andtest_where_array_like
fromTestInt64Index
to theNumericInt
base class for more generic coverage, and forced it to check that things get coerced toFloat64Index
. The way it was originally written raised a ValueError due to the 0 ->np.nan
change.