forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_copy_deprecation.py
91 lines (74 loc) · 2.8 KB
/
test_copy_deprecation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pytest
from pandas.util._exceptions import Pandas40DeprecationWarning
import pandas as pd
from pandas import (
concat,
merge,
)
import pandas._testing as tm
@pytest.mark.parametrize(
"meth, kwargs",
[
("truncate", {}),
("tz_convert", {"tz": "UTC"}),
("tz_localize", {"tz": "UTC"}),
("infer_objects", {}),
("astype", {"dtype": "float64"}),
("reindex", {"index": [2, 0, 1]}),
("transpose", {}),
("set_axis", {"labels": [1, 2, 3]}),
("rename", {"index": {1: 2}}),
("set_flags", {}),
("to_period", {}),
("to_timestamp", {}),
("swaplevel", {"i": 0, "j": 1}),
],
)
def test_copy_deprecation(meth, kwargs):
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": 1})
if meth in ("tz_convert", "tz_localize", "to_period"):
tz = None if meth in ("tz_localize", "to_period") else "US/Eastern"
df.index = pd.date_range("2020-01-01", freq="D", periods=len(df), tz=tz)
elif meth == "to_timestamp":
df.index = pd.period_range("2020-01-01", freq="D", periods=len(df))
elif meth == "swaplevel":
df = df.set_index(["b", "c"])
if meth != "swaplevel":
with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"):
getattr(df, meth)(copy=False, **kwargs)
if meth != "transpose":
with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"):
getattr(df.a, meth)(copy=False, **kwargs)
def test_copy_deprecation_reindex_like_align():
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
# Somehow the stack level check is incorrect here
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
df.reindex_like(df, copy=False)
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
df.a.reindex_like(df.a, copy=False)
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
df.align(df, copy=False)
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
df.a.align(df.a, copy=False)
def test_copy_deprecation_merge_concat():
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
df.merge(df, copy=False)
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
merge(df, df, copy=False)
with tm.assert_produces_warning(
Pandas40DeprecationWarning, match="copy", check_stacklevel=False
):
concat([df, df], copy=False)