-
-
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
ENH: Add dtype parameter to IntervalIndex constructors and deprecate from_intervals #19339
Conversation
@@ -1617,7 +1617,6 @@ IntervalIndex Components | |||
IntervalIndex.from_arrays | |||
IntervalIndex.from_tuples | |||
IntervalIndex.from_breaks | |||
IntervalIndex.from_intervals |
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.
Should this be removed from api.rst now, or should I wait until from_intervals
is actually deleted from the codebase and not just deprecated?
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.
yes this is fine
Codecov Report
@@ Coverage Diff @@
## master #19339 +/- ##
==========================================
- Coverage 91.61% 91.6% -0.02%
==========================================
Files 150 150
Lines 48677 48697 +20
==========================================
+ Hits 44595 44607 +12
- Misses 4082 4090 +8
Continue to review full report at Codecov.
|
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.
small comments. testing looks great!
@@ -1617,7 +1617,6 @@ IntervalIndex Components | |||
IntervalIndex.from_arrays | |||
IntervalIndex.from_tuples | |||
IntervalIndex.from_breaks | |||
IntervalIndex.from_intervals |
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.
yes this is fine
pandas/core/indexes/base.py
Outdated
@@ -200,7 +200,8 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, | |||
# interval | |||
if is_interval_dtype(data) or is_interval_dtype(dtype): | |||
from .interval import IntervalIndex | |||
return IntervalIndex(data, dtype=dtype, name=name, copy=copy) | |||
return IntervalIndex(data, dtype=dtype, name=name, copy=copy, | |||
**kwargs) |
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.
do we actually need kwargs to be passed or is that for consistentcy with others?
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's needed to pass closed
.
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 pass that directly?
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 by doing closed = kwargs.get('closed', None)
, then passing that into the constructor. Not sure if you meant doing it that way, or by adding closed=None
to the Index
constructor.
@@ -151,6 +152,8 @@ class IntervalIndex(IntervalMixin, Index): | |||
Name to be stored in the index. | |||
copy : boolean, default False | |||
Copy the meta-data | |||
dtype : dtype or None, default None | |||
If None, dtype will be inferred |
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.
add a version added
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
@@ -417,6 +427,8 @@ def from_breaks(cls, breaks, closed='right', name=None, copy=False): | |||
Name to be stored in the index. | |||
copy : boolean, default False | |||
copy the data | |||
dtype : dtype or None, default None | |||
If None, dtype will be inferred |
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.
vesionadded
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
@@ -458,6 +469,8 @@ def from_arrays(cls, left, right, closed='right', name=None, copy=False): | |||
Name to be stored in the index. | |||
copy : boolean, default False | |||
copy the data | |||
dtype : dtype or None, default None | |||
If None, dtype will be inferred |
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.
same
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
@@ -545,6 +559,8 @@ def from_tuples(cls, data, closed='right', name=None, copy=False): | |||
Name to be stored in the index. | |||
copy : boolean, default False | |||
by-default copy the data, this is compat only and ignored | |||
dtype : dtype or None, default None | |||
If None, dtype will be inferred |
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.
same
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/core/indexes/interval.py
Outdated
lhs, rhs = d | ||
except ValueError: | ||
msg = ('IntervalIndex.from_tuples requires tuples of ' | ||
'length 2, got {tpl}').format(tpl=d) |
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 we testing both of these paths?
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.
Yes, in TestFromTuples.test_constructor_errors
: testing tuples of length 1 and 3, as well as non-tuple input.
pandas/core/indexes/interval.py
Outdated
except TypeError: | ||
msg = ('IntervalIndex.from_tuples received an invalid ' | ||
'item, {tpl}').format(tpl=d) | ||
raise TypeError(msg) | ||
left.append(lhs) | ||
right.append(rhs) | ||
|
||
# TODO | ||
# if we have nulls and we previous had *only* | ||
# integer data, then we have changed the 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.
I think this comment is moot? (this was from me originally).....
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.
Agreed and removed. Was wondering about that comment but previously left it as-is in case there was something I missed; guess not.
7b56db9
to
213b8eb
Compare
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.
very minor comments. ping on green.
left = _ensure_index(left, copy=copy) | ||
right = _ensure_index(right, copy=copy) | ||
|
||
if dtype is not None: |
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 1-liner here, noting that this must be an interval 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.
done
@@ -571,15 +595,21 @@ def from_tuples(cls, data, closed='right', name=None, copy=False): | |||
if isna(d): | |||
lhs = rhs = np.nan | |||
else: | |||
lhs, rhs = d | |||
try: |
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 1-liner here showing the format of th expected input (list-of-tuples)
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
213b8eb
to
da2eac2
Compare
@jreback : green |
nice @jschendel keep em coming! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Summary:
dtype
parameter to all IntervalIndex constructorsIntervalIndex.from_intervals
dtype
parameter, since it's just a pass through toIntervalIndex
IntervalIndex.from_intervals
throughout the codebaseinterval/test_construction.py