-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: GH14323 Union of differences from DatetimeIndex incorrect #14346
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
|
||
v0.19.1 (????, 2016) | ||
-------------------- | ||
|
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.
remove the whatsnew things
they will be added independently
i = self.create_index() | ||
a = i[1:4] | ||
tm.assert_index_equal(i[:1].union(i[4:]), i.difference(a)) | ||
b = i[3:] |
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.
put expected on a separate line
# so a differencing operation should not retain the freq field of the | ||
# original index. | ||
i = self.create_index() | ||
self.assertIsNone(i.difference(i[1:3]).freq) |
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.
use assert_index_equal against a constructed expected index (same for ones below)
for dti and tdi do this in the superclass override for pi
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.
Thanks for the pointers, again I'm new to this.
One thing: if I want to test against an explicitly constructed expected index, I don't think I can do it in the superclass, can I? Wouldn't it have to be a different constructed index for each class (e.g. DatetimeIndex(["20130101", "20130105"])
, vs. TimedeltaIndex(["1 days", "5 days"])
? I can't use the self.indices field because the point is I need an index result that doesn't have a regular freq.
Also, assert_index_equal looks like it only compares freq for PeriodIndex, not DatetimeIndex:
if isinstance(left, pd.PeriodIndex) or isinstance(right, pd.PeriodIndex):
assert_attr_equal('freq', left, right, obj=obj)
which would ignore what I'm trying to test. Perhaps I could create a constructed index, run an assert_index_equal, and then run an explicit assert_attr_equal?
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.
assert_index_equal looks like it only compares freq for PeriodIndex
Indeed, that seems the case. So it is ok to still explicitly check the freq attribute to be None of the result
I can't use the self.indices field because the point is I need an index result that doesn't have a regular freq.
But the starting index should have a freq, no? So you can check the freq is reset to None after doing a difference?
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.
Sorry for the wait-- took me a bit to get the git to work (my own confusion). I've reverted the whatsnew changes and changed the tests to use explicit comparison indexes, at the expense of subclassing.
@jorisvandenbossche Happy to refactor the tests again to use subclassing if it's helpful, I'm just not sure I can do that and make the desired result explicit. From what I can tell, the way self.indices is constructed all of them correctly have freq Day
, so I can't use them as a desired result. Conversely if want to explicitly create a comparison index, I need to know what class I'm working with, since TimedeltaIndex
and DatetimeIndex
don't take the same set of string inputs.
Current coverage is 85.26% (diff: 100%)@@ master #14346 diff @@
==========================================
Files 140 140
Lines 50632 50632
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 43171 43172 +1
+ Misses 7461 7460 -1
Partials 0 0
|
Sets freq to None when doing a difference operation on a DatetimeIndex or TimedeltaIndex, rather than retaining the frequency (which can cause problems with downstream operations). Frequency of PeriodIndex is retained.
121d63c
to
1dbf582
Compare
Just bumping since my other comment was downthread-- I've reverted the whatsnew changes and made the tests use explicit comparisons, and then squashed the resulting commits. Glad to make a further refactor to the tests if you'd like. |
@Liam3851 Sorry for the delay in comment. |
thanks! |
… incorrect closes pandas-dev#14323 Sets freq to None when doing a difference operation on a DatetimeIndex or TimedeltaIndex, rather than retaining the frequency (which can cause problems with downstream operations). Frequency of PeriodIndex is retained. Author: David Krych <[email protected]> Closes pandas-dev#14346 from Liam3851/dtind_diff_14323 and squashes the following commits: 1dbf582 [David Krych] BUG: GH14323 Union of differences from DatetimeIndex incorrect (cherry picked from commit bee90a7)
git diff upstream/master | flake8 --diff
Sets freq to None when doing a difference operation on a DatetimeIndex
or TimedeltaIndex, rather than retaining the frequency (which can cause
problems with downstream operations). Frequency of PeriodIndex is
retained.