-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: IntervalIndex set op bugs for empty results #19112
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
743c2ba
to
e1bd5fe
Compare
Codecov Report
@@ Coverage Diff @@
## master #19112 +/- ##
==========================================
+ Coverage 91.52% 91.52% +<.01%
==========================================
Files 147 147
Lines 48775 48783 +8
==========================================
+ Hits 44639 44647 +8
Misses 4136 4136
Continue to review full report at Codecov.
|
e1bd5fe
to
46f6a86
Compare
generally just add this issue number on the previous whatnew entry |
pandas/core/indexes/interval.py
Outdated
def func(self, other): | ||
msg = ('can only do set operations between two IntervalIndex ' | ||
'objects that are closed on the same side') | ||
other = self._as_like_interval_index(other, msg) | ||
|
||
if check_subtypes: |
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.
why wouldn't you always check this?
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.
Operations between incompatible subtypes are technically valid for difference
and intersection
, since they always return a subset of the original index, so the left dtype can always be maintained:
In [2]: ii1 = pd.interval_range(0, 4)
In [3]: ii2 = pd.interval_range(pd.Timestamp('20180101'), periods=4)
In [4]: ii1.difference(ii2)
Out[4]:
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4]]
closed='right',
dtype='interval[int64]')
In [5]: ii1.intersection(ii2)
Out[5]:
IntervalIndex([]
closed='right',
dtype='interval[int64]')
While technically valid, not sure that difference
and intersection
really make sense for incompatible subtypes. Didn't want to immediately jump to raising for a technically valid op, but can certainly do the check for all set ops and always raise for incompatible subtypes, if that's the desired behavior.
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 I would rather not have a special check here. we simply don't want to allow ops between invalid types
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
46f6a86
to
7074a81
Compare
e46f0f1
to
ab550f1
Compare
ab550f1
to
49e0a49
Compare
thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Fixed bugs described in the issue:
float64
orobject
for empty results, depending on the op.Added an additional #19016 follow-up:
object
.union
betweeninterval[int64]
andinterval[datetime64[ns]]
.