Skip to content

Commit ea7b1d3

Browse files
committed
Merge branch 'main' into ref-split-pattern
2 parents 6b40155 + 0631637 commit ea7b1d3

File tree

22 files changed

+535
-531
lines changed

22 files changed

+535
-531
lines changed

ci/azure/posix.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,22 @@ parameters:
44

55
jobs:
66
- job: ${{ parameters.name }}
7+
timeoutInMinutes: 90
78
pool:
89
vmImage: ${{ parameters.vmImage }}
910
strategy:
1011
matrix:
11-
py38_macos_1:
12+
py38:
1213
ENV_FILE: ci/deps/azure-macos-38.yaml
1314
CONDA_PY: "38"
14-
PATTERN: "not slow and not single_cpu"
15-
PYTEST_TARGET: "pandas/tests/[a-h]*"
16-
py38_macos_2:
17-
ENV_FILE: ci/deps/azure-macos-38.yaml
18-
CONDA_PY: "38"
19-
PATTERN: "not slow and not single_cpu"
20-
PYTEST_TARGET: "pandas/tests/[i-z]*"
21-
py39_macos_1:
22-
ENV_FILE: ci/deps/azure-macos-39.yaml
23-
CONDA_PY: "39"
24-
PATTERN: "not slow and not single_cpu"
25-
PYTEST_TARGET: "pandas/tests/[a-h]*"
26-
py39_macos_2:
15+
16+
py39:
2717
ENV_FILE: ci/deps/azure-macos-39.yaml
2818
CONDA_PY: "39"
29-
PATTERN: "not slow and not single_cpu"
30-
PYTEST_TARGET: "pandas/tests/[i-z]*"
31-
py310_macos_1:
32-
ENV_FILE: ci/deps/azure-macos-310.yaml
33-
CONDA_PY: "310"
34-
PATTERN: "not slow and not single_cpu"
35-
PYTEST_TARGET: "pandas/tests/[a-h]*"
36-
py310_macos_2:
19+
20+
py310:
3721
ENV_FILE: ci/deps/azure-macos-310.yaml
3822
CONDA_PY: "310"
39-
PATTERN: "not slow and not single_cpu"
40-
PYTEST_TARGET: "pandas/tests/[i-z]*"
4123

4224
steps:
4325
- script: echo '##vso[task.prependpath]$(HOME)/miniconda3/bin'

doc/source/whatsnew/v1.5.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Other Deprecations
238238
- Deprecated behavior of :meth:`DatetimeIndex.intersection` and :meth:`DatetimeIndex.symmetric_difference` (``union`` behavior was already deprecated in version 1.3.0) with mixed time zones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`, :issue:`45357`)
239239
- Deprecated :meth:`DataFrame.iteritems`, :meth:`Series.iteritems`, :meth:`HDFStore.iteritems` in favor of :meth:`DataFrame.items`, :meth:`Series.items`, :meth:`HDFStore.items` (:issue:`45321`)
240240
- Deprecated :meth:`Series.is_monotonic` and :meth:`Index.is_monotonic` in favor of :meth:`Series.is_monotonic_increasing` and :meth:`Index.is_monotonic_increasing` (:issue:`45422`, :issue:`21335`)
241+
- Deprecated behavior of :meth:`DatetimeIndex.astype`, :meth:`TimedeltaIndex.astype`, :meth:`PeriodIndex.astype` when converting to an integer dtype other than ``int64``. In a future version, these will convert to exactly the specified dtype (instead of always ``int64``) and will raise if the conversion overflows (:issue:`45034`)
241242
- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`)
242243
- Deprecated the behavior of :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtype and incompatible fill value; in a future version this will cast to a common dtype (usually object) instead of raising, matching the behavior of other dtypes (:issue:`45746`)
243244
- Deprecated the ``warn`` parameter in :func:`infer_freq` (:issue:`45947`)

pandas/core/arrays/datetimelike.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,36 @@ def astype(self, dtype, copy: bool = True):
446446
if is_unsigned_integer_dtype(dtype):
447447
# Again, we ignore int32 vs. int64
448448
values = values.view("uint64")
449+
if dtype != np.uint64:
450+
# GH#45034
451+
warnings.warn(
452+
f"The behavior of .astype from {self.dtype} to {dtype} is "
453+
"deprecated. In a future version, this astype will return "
454+
"exactly the specified dtype instead of uint64, and will "
455+
"raise if that conversion overflows.",
456+
FutureWarning,
457+
stacklevel=find_stack_level(),
458+
)
459+
elif (self.asi8 < 0).any():
460+
# GH#45034
461+
warnings.warn(
462+
f"The behavior of .astype from {self.dtype} to {dtype} is "
463+
"deprecated. In a future version, this astype will "
464+
"raise if the conversion overflows, as it did in this "
465+
"case with negative int64 values.",
466+
FutureWarning,
467+
stacklevel=find_stack_level(),
468+
)
469+
elif dtype != np.int64:
470+
# GH#45034
471+
warnings.warn(
472+
f"The behavior of .astype from {self.dtype} to {dtype} is "
473+
"deprecated. In a future version, this astype will return "
474+
"exactly the specified dtype instead of int64, and will "
475+
"raise if that conversion overflows.",
476+
FutureWarning,
477+
stacklevel=find_stack_level(),
478+
)
449479

450480
if copy:
451481
values = values.copy()

pandas/tests/apply/test_str.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ def test_apply_with_string_funcs(request, float_frame, func, args, kwds, how):
4545
tm.assert_series_equal(result, expected)
4646

4747

48-
def test_with_string_args(datetime_series):
49-
50-
for arg in ["sum", "mean", "min", "max", "std"]:
51-
result = datetime_series.apply(arg)
52-
expected = getattr(datetime_series, arg)()
53-
assert result == expected
48+
@pytest.mark.parametrize("arg", ["sum", "mean", "min", "max", "std"])
49+
def test_with_string_args(datetime_series, arg):
50+
result = datetime_series.apply(arg)
51+
expected = getattr(datetime_series, arg)()
52+
assert result == expected
5453

5554

5655
@pytest.mark.parametrize("op", ["mean", "median", "std", "var"])

pandas/tests/arithmetic/test_numeric.py

Lines changed: 88 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from collections import abc
77
from decimal import Decimal
8-
from itertools import combinations
98
import operator
109
from typing import Any
1110

@@ -928,7 +927,6 @@ def test_datetime64_with_index(self):
928927
# TODO: taken from tests.frame.test_operators, needs cleanup
929928
def test_frame_operators(self, float_frame):
930929
frame = float_frame
931-
frame2 = pd.DataFrame(float_frame, columns=["D", "C", "B", "A"])
932930

933931
garbage = np.random.random(4)
934932
colSeries = Series(garbage, index=np.array(frame.columns))
@@ -952,23 +950,27 @@ def test_frame_operators(self, float_frame):
952950
else:
953951
assert np.isnan(origVal)
954952

953+
def test_frame_operators_col_align(self, float_frame):
954+
frame2 = pd.DataFrame(float_frame, columns=["D", "C", "B", "A"])
955955
added = frame2 + frame2
956956
expected = frame2 * 2
957957
tm.assert_frame_equal(added, expected)
958958

959+
def test_frame_operators_none_to_nan(self):
959960
df = pd.DataFrame({"a": ["a", None, "b"]})
960961
tm.assert_frame_equal(df + df, pd.DataFrame({"a": ["aa", np.nan, "bb"]}))
961962

963+
@pytest.mark.parametrize("dtype", ("float", "int64"))
964+
def test_frame_operators_empty_like(self, dtype):
962965
# Test for issue #10181
963-
for dtype in ("float", "int64"):
964-
frames = [
965-
pd.DataFrame(dtype=dtype),
966-
pd.DataFrame(columns=["A"], dtype=dtype),
967-
pd.DataFrame(index=[0], dtype=dtype),
968-
]
969-
for df in frames:
970-
assert (df + df).equals(df)
971-
tm.assert_frame_equal(df + df, df)
966+
frames = [
967+
pd.DataFrame(dtype=dtype),
968+
pd.DataFrame(columns=["A"], dtype=dtype),
969+
pd.DataFrame(index=[0], dtype=dtype),
970+
]
971+
for df in frames:
972+
assert (df + df).equals(df)
973+
tm.assert_frame_equal(df + df, df)
972974

973975
@pytest.mark.parametrize(
974976
"func",
@@ -1164,45 +1166,85 @@ def test_operators_reverse_object(self, op):
11641166
class TestNumericArithmeticUnsorted:
11651167
# Tests in this class have been moved from type-specific test modules
11661168
# but not yet sorted, parametrized, and de-duplicated
1167-
1168-
def check_binop(self, ops, scalars, idxs):
1169-
for op in ops:
1170-
for a, b in combinations(idxs, 2):
1171-
a = a._rename("foo")
1172-
b = b._rename("bar")
1173-
result = op(a, b)
1174-
expected = op(Int64Index(a), Int64Index(b))
1175-
tm.assert_index_equal(result, expected, exact="equiv")
1176-
for idx in idxs:
1177-
for scalar in scalars:
1178-
result = op(idx, scalar)
1179-
expected = op(Int64Index(idx), scalar)
1180-
tm.assert_index_equal(result, expected, exact="equiv")
1181-
1182-
def test_binops(self):
1183-
ops = [
1169+
@pytest.mark.parametrize(
1170+
"op",
1171+
[
11841172
operator.add,
11851173
operator.sub,
11861174
operator.mul,
11871175
operator.floordiv,
11881176
operator.truediv,
1189-
]
1190-
scalars = [-1, 1, 2]
1191-
idxs = [
1177+
],
1178+
)
1179+
@pytest.mark.parametrize(
1180+
"idx1",
1181+
[
11921182
RangeIndex(0, 10, 1),
11931183
RangeIndex(0, 20, 2),
11941184
RangeIndex(-10, 10, 2),
11951185
RangeIndex(5, -5, -1),
1196-
]
1197-
self.check_binop(ops, scalars, idxs)
1186+
],
1187+
)
1188+
@pytest.mark.parametrize(
1189+
"idx2",
1190+
[
1191+
RangeIndex(0, 10, 1),
1192+
RangeIndex(0, 20, 2),
1193+
RangeIndex(-10, 10, 2),
1194+
RangeIndex(5, -5, -1),
1195+
],
1196+
)
1197+
def test_binops_index(self, op, idx1, idx2):
1198+
idx1 = idx1._rename("foo")
1199+
idx2 = idx2._rename("bar")
1200+
result = op(idx1, idx2)
1201+
expected = op(Int64Index(idx1), Int64Index(idx2))
1202+
tm.assert_index_equal(result, expected, exact="equiv")
11981203

1199-
def test_binops_pow(self):
1204+
@pytest.mark.parametrize(
1205+
"op",
1206+
[
1207+
operator.add,
1208+
operator.sub,
1209+
operator.mul,
1210+
operator.floordiv,
1211+
operator.truediv,
1212+
],
1213+
)
1214+
@pytest.mark.parametrize(
1215+
"idx",
1216+
[
1217+
RangeIndex(0, 10, 1),
1218+
RangeIndex(0, 20, 2),
1219+
RangeIndex(-10, 10, 2),
1220+
RangeIndex(5, -5, -1),
1221+
],
1222+
)
1223+
@pytest.mark.parametrize("scalar", [-1, 1, 2])
1224+
def test_binops_index_scalar(self, op, idx, scalar):
1225+
result = op(idx, scalar)
1226+
expected = op(Int64Index(idx), scalar)
1227+
tm.assert_index_equal(result, expected, exact="equiv")
1228+
1229+
@pytest.mark.parametrize("idx1", [RangeIndex(0, 10, 1), RangeIndex(0, 20, 2)])
1230+
@pytest.mark.parametrize("idx2", [RangeIndex(0, 10, 1), RangeIndex(0, 20, 2)])
1231+
def test_binops_index_pow(self, idx1, idx2):
12001232
# numpy does not allow powers of negative integers so test separately
12011233
# https://github.com/numpy/numpy/pull/8127
1202-
ops = [pow]
1203-
scalars = [1, 2]
1204-
idxs = [RangeIndex(0, 10, 1), RangeIndex(0, 20, 2)]
1205-
self.check_binop(ops, scalars, idxs)
1234+
idx1 = idx1._rename("foo")
1235+
idx2 = idx2._rename("bar")
1236+
result = pow(idx1, idx2)
1237+
expected = pow(Int64Index(idx1), Int64Index(idx2))
1238+
tm.assert_index_equal(result, expected, exact="equiv")
1239+
1240+
@pytest.mark.parametrize("idx", [RangeIndex(0, 10, 1), RangeIndex(0, 20, 2)])
1241+
@pytest.mark.parametrize("scalar", [1, 2])
1242+
def test_binops_index_scalar_pow(self, idx, scalar):
1243+
# numpy does not allow powers of negative integers so test separately
1244+
# https://github.com/numpy/numpy/pull/8127
1245+
result = pow(idx, scalar)
1246+
expected = pow(Int64Index(idx), scalar)
1247+
tm.assert_index_equal(result, expected, exact="equiv")
12061248

12071249
# TODO: divmod?
12081250
@pytest.mark.parametrize(
@@ -1273,8 +1315,9 @@ def test_numeric_compat2(self):
12731315
expected = Int64Index(idx._values) ** 2
12741316
tm.assert_index_equal(Index(result.values), expected, exact=True)
12751317

1276-
# __floordiv__
1277-
cases_exact = [
1318+
@pytest.mark.parametrize(
1319+
"idx, div, expected",
1320+
[
12781321
(RangeIndex(0, 1000, 2), 2, RangeIndex(0, 500, 1)),
12791322
(RangeIndex(-99, -201, -3), -3, RangeIndex(33, 67, 1)),
12801323
(
@@ -1291,9 +1334,11 @@ def test_numeric_compat2(self):
12911334
(RangeIndex(2, 4, 2), 3, RangeIndex(0, 1, 1)),
12921335
(RangeIndex(-5, -10, -6), 4, RangeIndex(-2, -1, 1)),
12931336
(RangeIndex(-100, -200, 3), 2, RangeIndex(0)),
1294-
]
1295-
for idx, div, expected in cases_exact:
1296-
tm.assert_index_equal(idx // div, expected, exact=True)
1337+
],
1338+
)
1339+
def test_numeric_compat2_floordiv(self, idx, div, expected):
1340+
# __floordiv__
1341+
tm.assert_index_equal(idx // div, expected, exact=True)
12971342

12981343
@pytest.mark.parametrize("dtype", [np.int64, np.float64])
12991344
@pytest.mark.parametrize("delta", [1, 0, -1])

0 commit comments

Comments
 (0)