-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Prohibit non-numeric dtypes in IntervalIndex #19022
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
Conversation
pandas/core/indexes/interval.py
Outdated
if isinstance(data, (list, tuple)) and len(data) == 0: | ||
# GH 19016 | ||
# empty lists/tuples get object dtype by default, but this is not | ||
# prohibited for IntervalIndex, so coerce to integer instead |
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.
The comment here refers to the existing behavior of constructing an IntervalIndex
from an empty list:
In [2]: pd.IntervalIndex([])
Out[2]:
IntervalIndex([]
closed='right',
dtype='interval[object]')
The changes in this PR caused this to raise, since the inferred subtype was object, which is now being disallowed. Changed this to be instead be integer by default. Don't have any strong reason for choosing integer, so can change.
rebase and push again, fixed some hanging by Travis CI |
6c0eb8c
to
c2a9126
Compare
Codecov Report
@@ Coverage Diff @@
## master #19022 +/- ##
=========================================
Coverage ? 91.53%
=========================================
Files ? 148
Lines ? 48814
Branches ? 0
=========================================
Hits ? 44683
Misses ? 4131
Partials ? 0
Continue to review full report at Codecov.
|
@@ -4,7 +4,7 @@ | |||
import numpy as np | |||
from pandas import ( | |||
Interval, IntervalIndex, Index, isna, notna, interval_range, Timestamp, |
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 believe your test for .length
should change? IIRC you were catching he exception
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.
.length
had two tests: test_length
and test_length_errors
. I've removed test_length_errors
in full, since we should be prohibiting dtypes that would cause exceptions. I've left test_length
unchanged since it was only testing valid dtypes.
pandas/core/indexes/interval.py
Outdated
@@ -92,6 +94,18 @@ def _get_interval_closed_bounds(interval): | |||
return left, right | |||
|
|||
|
|||
def _maybe_convert_platform_interval(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.
can you add a doc-string, you can de-privatize (no leading _)
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
839a768
to
ca6ebe8
Compare
thanks @jschendel |
git diff upstream/master -u -- "*.py" | flake8 --diff