-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG - remove scaling multiplier from Period
diff result
#23915
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
Changes from 9 commits
377f6d1
b9fe48a
c262453
364d4a9
713484c
d0a5afe
7ebe407
e8b4c4a
9ad13d8
a38ba5a
cd7bb21
9a369a6
c8f36b9
3206144
4b83c3a
1db7bb0
c9a83d6
7c4e3e6
c128a1f
e6d35e6
ae189ea
8aaf19e
9ed3629
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1685,7 +1685,9 @@ cdef class _Period(object): | |
if other.freq != self.freq: | ||
msg = _DIFFERENT_FREQ.format(self.freqstr, other.freqstr) | ||
raise IncompatibleFrequency(msg) | ||
return (self.ordinal - other.ordinal) * self.freq | ||
base_freq = type(self.freq)(normalize=self.freq.normalize, | ||
**self.freq.kwds) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pass add a reference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return (self.ordinal - other.ordinal) * base_freq | ||
elif getattr(other, '_typ', None) == 'periodindex': | ||
# GH#21314 PeriodIndex - Period returns an object-index | ||
# of DateOffset objects, for which we cannot use __neg__ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1106,6 +1106,38 @@ def test_sub(self): | |
with pytest.raises(period.IncompatibleFrequency, match=msg): | ||
per1 - Period('2011-02', freq='M') | ||
|
||
@pytest.mark.parametrize('kwds', [ | ||
{}, | ||
{'normalize': True}, | ||
{'normalize': False}, | ||
{'normalize': True, 'month': 4}, | ||
{'normalize': False, 'month': 4}, | ||
]) | ||
@pytest.mark.parametrize('n', [1, 2, 3, 4]) | ||
@pytest.mark.parametrize('freq,expected', [ | ||
(pd.offsets.Second, 18489600), | ||
(pd.offsets.Minute, 308160), | ||
(pd.offsets.Hour, 5136), | ||
(pd.offsets.Day, 214), | ||
(pd.offsets.MonthEnd, 7), | ||
(pd.offsets.YearEnd, 1), | ||
]) | ||
def test_sub_non_standard_freq(self, freq, expected, n, kwds): | ||
# GH 23878 | ||
# Only kwd allowed in period compatible freqs is 'month' in `YearEnd` | ||
if 'month' in kwds: | ||
if freq is pd.offsets.YearEnd: | ||
expected = 0 | ||
else: | ||
return | ||
# Only non-Tick frequencies can have normalize set to True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably cleaner to test separately also this gets a couple of non-tick frequencies, but using the structure in tests.tseries.offsets should make it feasible to be a lot more thorough There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separated. |
||
if pd.tseries.offsets.Tick in freq.__bases__ and kwds.get('normalize'): | ||
return | ||
|
||
p1 = pd.Period('19910905', freq=freq(n, **kwds)) | ||
p2 = pd.Period('19920406', freq=freq(n, **kwds)) | ||
assert (p2 - p1) == freq(expected, **kwds) | ||
|
||
def test_add_offset(self): | ||
# freq is DateOffset | ||
for freq in ['A', '2A', '3A']: | ||
|
Uh oh!
There was an error while loading. Please reload this page.