+16
-2
lines changedFilter options
+16
-2
lines changed Original file line number Diff line number Diff line change
@@ -829,6 +829,7 @@ Period
829
829
- Bug in inferring an incorrect ``freq`` when passing a string to :class:`Period` microseconds that are a multiple of 1000 (:issue:`46811`)
830
830
- Bug in constructing a :class:`Period` from a :class:`Timestamp` or ``np.datetime64`` object with non-zero nanoseconds and ``freq="ns"`` incorrectly truncating the nanoseconds (:issue:`46811`)
831
831
- Bug in adding ``np.timedelta64("NaT", "ns")`` to a :class:`Period` with a timedelta-like freq incorrectly raising ``IncompatibleFrequency`` instead of returning ``NaT`` (:issue:`47196`)
832
+
- Bug in adding an array of integers to an array with :class:`PeriodDtype` giving incorrect results when ``dtype.freq.n > 1`` (:issue:`47209`)
832
833
-
833
834
834
835
Plotting
Original file line number Diff line number Diff line change
@@ -1317,7 +1317,7 @@ def __add__(self, other):
1317
1317
if not is_period_dtype(self.dtype):
1318
1318
raise integer_op_not_supported(self)
1319
1319
result = cast("PeriodArray", self)._addsub_int_array_or_scalar(
1320
-
other, operator.add
1320
+
other * self.freq.n, operator.add
1321
1321
)
1322
1322
else:
1323
1323
# Includes Categorical, other ExtensionArrays
@@ -1379,7 +1379,7 @@ def __sub__(self, other):
1379
1379
if not is_period_dtype(self.dtype):
1380
1380
raise integer_op_not_supported(self)
1381
1381
result = cast("PeriodArray", self)._addsub_int_array_or_scalar(
1382
-
other, operator.sub
1382
+
other * self.freq.n, operator.sub
1383
1383
)
1384
1384
else:
1385
1385
# Includes ExtensionArrays, float_dtype
Original file line number Diff line number Diff line change
@@ -914,6 +914,19 @@ def test_pi_sub_intlike(self, five):
914
914
exp = rng + (-five)
915
915
tm.assert_index_equal(result, exp)
916
916
917
+
def test_pi_add_sub_int_array_freqn_gt1(self):
918
+
# GH#47209 test adding array of ints when freq.n > 1 matches
919
+
# scalar behavior
920
+
pi = period_range("2016-01-01", periods=10, freq="2D")
921
+
arr = np.arange(10)
922
+
result = pi + arr
923
+
expected = pd.Index([x + y for x, y in zip(pi, arr)])
924
+
tm.assert_index_equal(result, expected)
925
+
926
+
result = pi - arr
927
+
expected = pd.Index([x - y for x, y in zip(pi, arr)])
928
+
tm.assert_index_equal(result, expected)
929
+
917
930
def test_pi_sub_isub_offset(self):
918
931
# offset
919
932
# DateOffset
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4