-
-
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 7 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,7 @@ 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 | ||
return (self.ordinal - other.ordinal) * type(self.freq)() | ||
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. Won't this be wrong for offsets that have relevant keywords? 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. You’re right. So one option would be to do
This way no other classes need to be modified. However, I think it might be worth adding a property to the DateOffset objet to do the above suggestion. Something like 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. fixed |
||
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 |
---|---|---|
|
@@ -1085,3 +1085,21 @@ def test_pi_sub_period_nat(self): | |
exp = pd.TimedeltaIndex([np.nan, np.nan, np.nan, np.nan], name='idx') | ||
tm.assert_index_equal(idx - pd.Period('NaT', freq='M'), exp) | ||
tm.assert_index_equal(pd.Period('NaT', freq='M') - idx, exp) | ||
|
||
|
||
class TestPeriodArithmetic(object): | ||
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. This all belongs in pandas.tests.scalar.period. If you want to make a new file test_arithmetic.py in that directory, that'd be OK. Otherwise put in test_period.py 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. moved |
||
|
||
@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), | ||
]) | ||
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. definitely needs cases with kwargs passed to offset constructors. Putting it in tests.tseries.offsets might be useful since there are test classes that construct a bunch of these 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. parameterized the tests on some kwargs too, only YearEnd takes any kwds besides normalize ('month'). And only non-Tick offsets (in this case MonthEnd and YearEnd) can take normalize=True. |
||
def test_period_diff(self, freq, expected, n): | ||
# GH 23878 | ||
p1 = pd.Period('19910905', freq=freq(n)) | ||
p2 = pd.Period('19920406', freq=freq(n)) | ||
assert (p2 - p1) == freq(expected) |
Uh oh!
There was an error while loading. Please reload this page.