applied-ai-018 commited on
Commit
5c0cb19
·
verified ·
1 Parent(s): a878579

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ckpts/universal/global_step80/zero/12.mlp.dense_4h_to_h.weight/exp_avg.pt +3 -0
  2. ckpts/universal/global_step80/zero/12.mlp.dense_4h_to_h.weight/fp32.pt +3 -0
  3. ckpts/universal/global_step80/zero/18.attention.dense.weight/exp_avg_sq.pt +3 -0
  4. ckpts/universal/global_step80/zero/18.attention.dense.weight/fp32.pt +3 -0
  5. venv/lib/python3.10/site-packages/pandas/tests/util/__init__.py +0 -0
  6. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/__init__.cpython-310.pyc +0 -0
  7. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_assert_index_equal.cpython-310.pyc +0 -0
  8. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_deprecate_kwarg.cpython-310.pyc +0 -0
  9. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_deprecate_nonkeyword_arguments.cpython-310.pyc +0 -0
  10. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_hashing.cpython-310.pyc +0 -0
  11. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_numba.cpython-310.pyc +0 -0
  12. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_shares_memory.cpython-310.pyc +0 -0
  13. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_show_versions.cpython-310.pyc +0 -0
  14. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_util.cpython-310.pyc +0 -0
  15. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_validate_inclusive.cpython-310.pyc +0 -0
  16. venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_validate_kwargs.cpython-310.pyc +0 -0
  17. venv/lib/python3.10/site-packages/pandas/tests/util/conftest.py +26 -0
  18. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_almost_equal.py +586 -0
  19. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_attr_equal.py +33 -0
  20. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_categorical_equal.py +90 -0
  21. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_extension_array_equal.py +126 -0
  22. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_frame_equal.py +393 -0
  23. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_index_equal.py +319 -0
  24. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_interval_array_equal.py +81 -0
  25. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_numpy_array_equal.py +223 -0
  26. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_produces_warning.py +241 -0
  27. venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_series_equal.py +484 -0
  28. venv/lib/python3.10/site-packages/pandas/tests/util/test_deprecate.py +63 -0
  29. venv/lib/python3.10/site-packages/pandas/tests/util/test_deprecate_kwarg.py +90 -0
  30. venv/lib/python3.10/site-packages/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +141 -0
  31. venv/lib/python3.10/site-packages/pandas/tests/util/test_doc.py +90 -0
  32. venv/lib/python3.10/site-packages/pandas/tests/util/test_hashing.py +417 -0
  33. venv/lib/python3.10/site-packages/pandas/tests/util/test_numba.py +12 -0
  34. venv/lib/python3.10/site-packages/pandas/tests/util/test_rewrite_warning.py +39 -0
  35. venv/lib/python3.10/site-packages/pandas/tests/util/test_shares_memory.py +30 -0
  36. venv/lib/python3.10/site-packages/pandas/tests/util/test_show_versions.py +81 -0
  37. venv/lib/python3.10/site-packages/pandas/tests/util/test_util.py +58 -0
  38. venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_args.py +70 -0
  39. venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_args_and_kwargs.py +84 -0
  40. venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_inclusive.py +40 -0
  41. venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_kwargs.py +69 -0
  42. venv/lib/python3.10/site-packages/pandas/tests/window/__init__.py +0 -0
  43. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/__init__.cpython-310.pyc +0 -0
  44. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/conftest.cpython-310.pyc +0 -0
  45. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_api.cpython-310.pyc +0 -0
  46. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_apply.cpython-310.pyc +0 -0
  47. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_base_indexer.cpython-310.pyc +0 -0
  48. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_cython_aggregations.cpython-310.pyc +0 -0
  49. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_dtypes.cpython-310.pyc +0 -0
  50. venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_ewm.cpython-310.pyc +0 -0
ckpts/universal/global_step80/zero/12.mlp.dense_4h_to_h.weight/exp_avg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5c492ef7323e9778e2e7887b628fa7406ac2b9feb7c6d5a990517b8b2e460f1d
3
+ size 33555612
ckpts/universal/global_step80/zero/12.mlp.dense_4h_to_h.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a01af5fc18b569671c412749be233fe5ced19cccff2efd149c77e3cea691bf9a
3
+ size 33555533
ckpts/universal/global_step80/zero/18.attention.dense.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7bb14cae8b574f54751f6dc8b365ea237aece310ed99f01d6691f40398dea47
3
+ size 16778411
ckpts/universal/global_step80/zero/18.attention.dense.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:378aa28550d3495a4f3738153c6c88bb18abfd65b19d375a3e085e39fe3f4644
3
+ size 16778317
venv/lib/python3.10/site-packages/pandas/tests/util/__init__.py ADDED
File without changes
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (185 Bytes). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_assert_index_equal.cpython-310.pyc ADDED
Binary file (9.55 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_deprecate_kwarg.cpython-310.pyc ADDED
Binary file (3.12 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_deprecate_nonkeyword_arguments.cpython-310.pyc ADDED
Binary file (5.45 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_hashing.cpython-310.pyc ADDED
Binary file (11.7 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_numba.cpython-310.pyc ADDED
Binary file (693 Bytes). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_shares_memory.cpython-310.pyc ADDED
Binary file (1.06 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_show_versions.cpython-310.pyc ADDED
Binary file (1.77 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_util.cpython-310.pyc ADDED
Binary file (2.04 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_validate_inclusive.cpython-310.pyc ADDED
Binary file (1.04 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/__pycache__/test_validate_kwargs.cpython-310.pyc ADDED
Binary file (2.17 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/util/conftest.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+
4
+ @pytest.fixture(params=[True, False])
5
+ def check_dtype(request):
6
+ return request.param
7
+
8
+
9
+ @pytest.fixture(params=[True, False])
10
+ def check_exact(request):
11
+ return request.param
12
+
13
+
14
+ @pytest.fixture(params=[True, False])
15
+ def check_index_type(request):
16
+ return request.param
17
+
18
+
19
+ @pytest.fixture(params=[0.5e-3, 0.5e-5])
20
+ def rtol(request):
21
+ return request.param
22
+
23
+
24
+ @pytest.fixture(params=[True, False])
25
+ def check_categorical(request):
26
+ return request.param
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_almost_equal.py ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ NA,
6
+ DataFrame,
7
+ Index,
8
+ NaT,
9
+ Series,
10
+ Timestamp,
11
+ )
12
+ import pandas._testing as tm
13
+
14
+
15
+ def _assert_almost_equal_both(a, b, **kwargs):
16
+ """
17
+ Check that two objects are approximately equal.
18
+
19
+ This check is performed commutatively.
20
+
21
+ Parameters
22
+ ----------
23
+ a : object
24
+ The first object to compare.
25
+ b : object
26
+ The second object to compare.
27
+ **kwargs
28
+ The arguments passed to `tm.assert_almost_equal`.
29
+ """
30
+ tm.assert_almost_equal(a, b, **kwargs)
31
+ tm.assert_almost_equal(b, a, **kwargs)
32
+
33
+
34
+ def _assert_not_almost_equal(a, b, **kwargs):
35
+ """
36
+ Check that two objects are not approximately equal.
37
+
38
+ Parameters
39
+ ----------
40
+ a : object
41
+ The first object to compare.
42
+ b : object
43
+ The second object to compare.
44
+ **kwargs
45
+ The arguments passed to `tm.assert_almost_equal`.
46
+ """
47
+ try:
48
+ tm.assert_almost_equal(a, b, **kwargs)
49
+ msg = f"{a} and {b} were approximately equal when they shouldn't have been"
50
+ pytest.fail(reason=msg)
51
+ except AssertionError:
52
+ pass
53
+
54
+
55
+ def _assert_not_almost_equal_both(a, b, **kwargs):
56
+ """
57
+ Check that two objects are not approximately equal.
58
+
59
+ This check is performed commutatively.
60
+
61
+ Parameters
62
+ ----------
63
+ a : object
64
+ The first object to compare.
65
+ b : object
66
+ The second object to compare.
67
+ **kwargs
68
+ The arguments passed to `tm.assert_almost_equal`.
69
+ """
70
+ _assert_not_almost_equal(a, b, **kwargs)
71
+ _assert_not_almost_equal(b, a, **kwargs)
72
+
73
+
74
+ @pytest.mark.parametrize(
75
+ "a,b",
76
+ [
77
+ (1.1, 1.1),
78
+ (1.1, 1.100001),
79
+ (np.int16(1), 1.000001),
80
+ (np.float64(1.1), 1.1),
81
+ (np.uint32(5), 5),
82
+ ],
83
+ )
84
+ def test_assert_almost_equal_numbers(a, b):
85
+ _assert_almost_equal_both(a, b)
86
+
87
+
88
+ @pytest.mark.parametrize(
89
+ "a,b",
90
+ [
91
+ (1.1, 1),
92
+ (1.1, True),
93
+ (1, 2),
94
+ (1.0001, np.int16(1)),
95
+ # The following two examples are not "almost equal" due to tol.
96
+ (0.1, 0.1001),
97
+ (0.0011, 0.0012),
98
+ ],
99
+ )
100
+ def test_assert_not_almost_equal_numbers(a, b):
101
+ _assert_not_almost_equal_both(a, b)
102
+
103
+
104
+ @pytest.mark.parametrize(
105
+ "a,b",
106
+ [
107
+ (1.1, 1.1),
108
+ (1.1, 1.100001),
109
+ (1.1, 1.1001),
110
+ (0.000001, 0.000005),
111
+ (1000.0, 1000.0005),
112
+ # Testing this example, as per #13357
113
+ (0.000011, 0.000012),
114
+ ],
115
+ )
116
+ def test_assert_almost_equal_numbers_atol(a, b):
117
+ # Equivalent to the deprecated check_less_precise=True, enforced in 2.0
118
+ _assert_almost_equal_both(a, b, rtol=0.5e-3, atol=0.5e-3)
119
+
120
+
121
+ @pytest.mark.parametrize("a,b", [(1.1, 1.11), (0.1, 0.101), (0.000011, 0.001012)])
122
+ def test_assert_not_almost_equal_numbers_atol(a, b):
123
+ _assert_not_almost_equal_both(a, b, atol=1e-3)
124
+
125
+
126
+ @pytest.mark.parametrize(
127
+ "a,b",
128
+ [
129
+ (1.1, 1.1),
130
+ (1.1, 1.100001),
131
+ (1.1, 1.1001),
132
+ (1000.0, 1000.0005),
133
+ (1.1, 1.11),
134
+ (0.1, 0.101),
135
+ ],
136
+ )
137
+ def test_assert_almost_equal_numbers_rtol(a, b):
138
+ _assert_almost_equal_both(a, b, rtol=0.05)
139
+
140
+
141
+ @pytest.mark.parametrize("a,b", [(0.000011, 0.000012), (0.000001, 0.000005)])
142
+ def test_assert_not_almost_equal_numbers_rtol(a, b):
143
+ _assert_not_almost_equal_both(a, b, rtol=0.05)
144
+
145
+
146
+ @pytest.mark.parametrize(
147
+ "a,b,rtol",
148
+ [
149
+ (1.00001, 1.00005, 0.001),
150
+ (-0.908356 + 0.2j, -0.908358 + 0.2j, 1e-3),
151
+ (0.1 + 1.009j, 0.1 + 1.006j, 0.1),
152
+ (0.1001 + 2.0j, 0.1 + 2.001j, 0.01),
153
+ ],
154
+ )
155
+ def test_assert_almost_equal_complex_numbers(a, b, rtol):
156
+ _assert_almost_equal_both(a, b, rtol=rtol)
157
+ _assert_almost_equal_both(np.complex64(a), np.complex64(b), rtol=rtol)
158
+ _assert_almost_equal_both(np.complex128(a), np.complex128(b), rtol=rtol)
159
+
160
+
161
+ @pytest.mark.parametrize(
162
+ "a,b,rtol",
163
+ [
164
+ (0.58310768, 0.58330768, 1e-7),
165
+ (-0.908 + 0.2j, -0.978 + 0.2j, 0.001),
166
+ (0.1 + 1j, 0.1 + 2j, 0.01),
167
+ (-0.132 + 1.001j, -0.132 + 1.005j, 1e-5),
168
+ (0.58310768j, 0.58330768j, 1e-9),
169
+ ],
170
+ )
171
+ def test_assert_not_almost_equal_complex_numbers(a, b, rtol):
172
+ _assert_not_almost_equal_both(a, b, rtol=rtol)
173
+ _assert_not_almost_equal_both(np.complex64(a), np.complex64(b), rtol=rtol)
174
+ _assert_not_almost_equal_both(np.complex128(a), np.complex128(b), rtol=rtol)
175
+
176
+
177
+ @pytest.mark.parametrize("a,b", [(0, 0), (0, 0.0), (0, np.float64(0)), (0.00000001, 0)])
178
+ def test_assert_almost_equal_numbers_with_zeros(a, b):
179
+ _assert_almost_equal_both(a, b)
180
+
181
+
182
+ @pytest.mark.parametrize("a,b", [(0.001, 0), (1, 0)])
183
+ def test_assert_not_almost_equal_numbers_with_zeros(a, b):
184
+ _assert_not_almost_equal_both(a, b)
185
+
186
+
187
+ @pytest.mark.parametrize("a,b", [(1, "abc"), (1, [1]), (1, object())])
188
+ def test_assert_not_almost_equal_numbers_with_mixed(a, b):
189
+ _assert_not_almost_equal_both(a, b)
190
+
191
+
192
+ @pytest.mark.parametrize(
193
+ "left_dtype", ["M8[ns]", "m8[ns]", "float64", "int64", "object"]
194
+ )
195
+ @pytest.mark.parametrize(
196
+ "right_dtype", ["M8[ns]", "m8[ns]", "float64", "int64", "object"]
197
+ )
198
+ def test_assert_almost_equal_edge_case_ndarrays(left_dtype, right_dtype):
199
+ # Empty compare.
200
+ _assert_almost_equal_both(
201
+ np.array([], dtype=left_dtype),
202
+ np.array([], dtype=right_dtype),
203
+ check_dtype=False,
204
+ )
205
+
206
+
207
+ def test_assert_almost_equal_sets():
208
+ # GH#51727
209
+ _assert_almost_equal_both({1, 2, 3}, {1, 2, 3})
210
+
211
+
212
+ def test_assert_almost_not_equal_sets():
213
+ # GH#51727
214
+ msg = r"{1, 2, 3} != {1, 2, 4}"
215
+ with pytest.raises(AssertionError, match=msg):
216
+ _assert_almost_equal_both({1, 2, 3}, {1, 2, 4})
217
+
218
+
219
+ def test_assert_almost_equal_dicts():
220
+ _assert_almost_equal_both({"a": 1, "b": 2}, {"a": 1, "b": 2})
221
+
222
+
223
+ @pytest.mark.parametrize(
224
+ "a,b",
225
+ [
226
+ ({"a": 1, "b": 2}, {"a": 1, "b": 3}),
227
+ ({"a": 1, "b": 2}, {"a": 1, "b": 2, "c": 3}),
228
+ ({"a": 1}, 1),
229
+ ({"a": 1}, "abc"),
230
+ ({"a": 1}, [1]),
231
+ ],
232
+ )
233
+ def test_assert_not_almost_equal_dicts(a, b):
234
+ _assert_not_almost_equal_both(a, b)
235
+
236
+
237
+ @pytest.mark.parametrize("val", [1, 2])
238
+ def test_assert_almost_equal_dict_like_object(val):
239
+ dict_val = 1
240
+ real_dict = {"a": val}
241
+
242
+ class DictLikeObj:
243
+ def keys(self):
244
+ return ("a",)
245
+
246
+ def __getitem__(self, item):
247
+ if item == "a":
248
+ return dict_val
249
+
250
+ func = (
251
+ _assert_almost_equal_both if val == dict_val else _assert_not_almost_equal_both
252
+ )
253
+ func(real_dict, DictLikeObj(), check_dtype=False)
254
+
255
+
256
+ def test_assert_almost_equal_strings():
257
+ _assert_almost_equal_both("abc", "abc")
258
+
259
+
260
+ @pytest.mark.parametrize(
261
+ "a,b", [("abc", "abcd"), ("abc", "abd"), ("abc", 1), ("abc", [1])]
262
+ )
263
+ def test_assert_not_almost_equal_strings(a, b):
264
+ _assert_not_almost_equal_both(a, b)
265
+
266
+
267
+ @pytest.mark.parametrize(
268
+ "a,b", [([1, 2, 3], [1, 2, 3]), (np.array([1, 2, 3]), np.array([1, 2, 3]))]
269
+ )
270
+ def test_assert_almost_equal_iterables(a, b):
271
+ _assert_almost_equal_both(a, b)
272
+
273
+
274
+ @pytest.mark.parametrize(
275
+ "a,b",
276
+ [
277
+ # Class is different.
278
+ (np.array([1, 2, 3]), [1, 2, 3]),
279
+ # Dtype is different.
280
+ (np.array([1, 2, 3]), np.array([1.0, 2.0, 3.0])),
281
+ # Can't compare generators.
282
+ (iter([1, 2, 3]), [1, 2, 3]),
283
+ ([1, 2, 3], [1, 2, 4]),
284
+ ([1, 2, 3], [1, 2, 3, 4]),
285
+ ([1, 2, 3], 1),
286
+ ],
287
+ )
288
+ def test_assert_not_almost_equal_iterables(a, b):
289
+ _assert_not_almost_equal(a, b)
290
+
291
+
292
+ def test_assert_almost_equal_null():
293
+ _assert_almost_equal_both(None, None)
294
+
295
+
296
+ @pytest.mark.parametrize("a,b", [(None, np.nan), (None, 0), (np.nan, 0)])
297
+ def test_assert_not_almost_equal_null(a, b):
298
+ _assert_not_almost_equal(a, b)
299
+
300
+
301
+ @pytest.mark.parametrize(
302
+ "a,b",
303
+ [
304
+ (np.inf, np.inf),
305
+ (np.inf, float("inf")),
306
+ (np.array([np.inf, np.nan, -np.inf]), np.array([np.inf, np.nan, -np.inf])),
307
+ ],
308
+ )
309
+ def test_assert_almost_equal_inf(a, b):
310
+ _assert_almost_equal_both(a, b)
311
+
312
+
313
+ objs = [NA, np.nan, NaT, None, np.datetime64("NaT"), np.timedelta64("NaT")]
314
+
315
+
316
+ @pytest.mark.parametrize("left", objs)
317
+ @pytest.mark.parametrize("right", objs)
318
+ def test_mismatched_na_assert_almost_equal_deprecation(left, right):
319
+ left_arr = np.array([left], dtype=object)
320
+ right_arr = np.array([right], dtype=object)
321
+
322
+ msg = "Mismatched null-like values"
323
+
324
+ if left is right:
325
+ _assert_almost_equal_both(left, right, check_dtype=False)
326
+ tm.assert_numpy_array_equal(left_arr, right_arr)
327
+ tm.assert_index_equal(
328
+ Index(left_arr, dtype=object), Index(right_arr, dtype=object)
329
+ )
330
+ tm.assert_series_equal(
331
+ Series(left_arr, dtype=object), Series(right_arr, dtype=object)
332
+ )
333
+ tm.assert_frame_equal(
334
+ DataFrame(left_arr, dtype=object), DataFrame(right_arr, dtype=object)
335
+ )
336
+
337
+ else:
338
+ with tm.assert_produces_warning(FutureWarning, match=msg):
339
+ _assert_almost_equal_both(left, right, check_dtype=False)
340
+
341
+ # TODO: to get the same deprecation in assert_numpy_array_equal we need
342
+ # to change/deprecate the default for strict_nan to become True
343
+ # TODO: to get the same deprecation in assert_index_equal we need to
344
+ # change/deprecate array_equivalent_object to be stricter, as
345
+ # assert_index_equal uses Index.equal which uses array_equivalent.
346
+ with tm.assert_produces_warning(FutureWarning, match=msg):
347
+ tm.assert_series_equal(
348
+ Series(left_arr, dtype=object), Series(right_arr, dtype=object)
349
+ )
350
+ with tm.assert_produces_warning(FutureWarning, match=msg):
351
+ tm.assert_frame_equal(
352
+ DataFrame(left_arr, dtype=object), DataFrame(right_arr, dtype=object)
353
+ )
354
+
355
+
356
+ def test_assert_not_almost_equal_inf():
357
+ _assert_not_almost_equal_both(np.inf, 0)
358
+
359
+
360
+ @pytest.mark.parametrize(
361
+ "a,b",
362
+ [
363
+ (Index([1.0, 1.1]), Index([1.0, 1.100001])),
364
+ (Series([1.0, 1.1]), Series([1.0, 1.100001])),
365
+ (np.array([1.1, 2.000001]), np.array([1.1, 2.0])),
366
+ (DataFrame({"a": [1.0, 1.1]}), DataFrame({"a": [1.0, 1.100001]})),
367
+ ],
368
+ )
369
+ def test_assert_almost_equal_pandas(a, b):
370
+ _assert_almost_equal_both(a, b)
371
+
372
+
373
+ def test_assert_almost_equal_object():
374
+ a = [Timestamp("2011-01-01"), Timestamp("2011-01-01")]
375
+ b = [Timestamp("2011-01-01"), Timestamp("2011-01-01")]
376
+ _assert_almost_equal_both(a, b)
377
+
378
+
379
+ def test_assert_almost_equal_value_mismatch():
380
+ msg = "expected 2\\.00000 but got 1\\.00000, with rtol=1e-05, atol=1e-08"
381
+
382
+ with pytest.raises(AssertionError, match=msg):
383
+ tm.assert_almost_equal(1, 2)
384
+
385
+
386
+ @pytest.mark.parametrize(
387
+ "a,b,klass1,klass2",
388
+ [(np.array([1]), 1, "ndarray", "int"), (1, np.array([1]), "int", "ndarray")],
389
+ )
390
+ def test_assert_almost_equal_class_mismatch(a, b, klass1, klass2):
391
+ msg = f"""numpy array are different
392
+
393
+ numpy array classes are different
394
+ \\[left\\]: {klass1}
395
+ \\[right\\]: {klass2}"""
396
+
397
+ with pytest.raises(AssertionError, match=msg):
398
+ tm.assert_almost_equal(a, b)
399
+
400
+
401
+ def test_assert_almost_equal_value_mismatch1():
402
+ msg = """numpy array are different
403
+
404
+ numpy array values are different \\(66\\.66667 %\\)
405
+ \\[left\\]: \\[nan, 2\\.0, 3\\.0\\]
406
+ \\[right\\]: \\[1\\.0, nan, 3\\.0\\]"""
407
+
408
+ with pytest.raises(AssertionError, match=msg):
409
+ tm.assert_almost_equal(np.array([np.nan, 2, 3]), np.array([1, np.nan, 3]))
410
+
411
+
412
+ def test_assert_almost_equal_value_mismatch2():
413
+ msg = """numpy array are different
414
+
415
+ numpy array values are different \\(50\\.0 %\\)
416
+ \\[left\\]: \\[1, 2\\]
417
+ \\[right\\]: \\[1, 3\\]"""
418
+
419
+ with pytest.raises(AssertionError, match=msg):
420
+ tm.assert_almost_equal(np.array([1, 2]), np.array([1, 3]))
421
+
422
+
423
+ def test_assert_almost_equal_value_mismatch3():
424
+ msg = """numpy array are different
425
+
426
+ numpy array values are different \\(16\\.66667 %\\)
427
+ \\[left\\]: \\[\\[1, 2\\], \\[3, 4\\], \\[5, 6\\]\\]
428
+ \\[right\\]: \\[\\[1, 3\\], \\[3, 4\\], \\[5, 6\\]\\]"""
429
+
430
+ with pytest.raises(AssertionError, match=msg):
431
+ tm.assert_almost_equal(
432
+ np.array([[1, 2], [3, 4], [5, 6]]), np.array([[1, 3], [3, 4], [5, 6]])
433
+ )
434
+
435
+
436
+ def test_assert_almost_equal_value_mismatch4():
437
+ msg = """numpy array are different
438
+
439
+ numpy array values are different \\(25\\.0 %\\)
440
+ \\[left\\]: \\[\\[1, 2\\], \\[3, 4\\]\\]
441
+ \\[right\\]: \\[\\[1, 3\\], \\[3, 4\\]\\]"""
442
+
443
+ with pytest.raises(AssertionError, match=msg):
444
+ tm.assert_almost_equal(np.array([[1, 2], [3, 4]]), np.array([[1, 3], [3, 4]]))
445
+
446
+
447
+ def test_assert_almost_equal_shape_mismatch_override():
448
+ msg = """Index are different
449
+
450
+ Index shapes are different
451
+ \\[left\\]: \\(2L*,\\)
452
+ \\[right\\]: \\(3L*,\\)"""
453
+ with pytest.raises(AssertionError, match=msg):
454
+ tm.assert_almost_equal(np.array([1, 2]), np.array([3, 4, 5]), obj="Index")
455
+
456
+
457
+ def test_assert_almost_equal_unicode():
458
+ # see gh-20503
459
+ msg = """numpy array are different
460
+
461
+ numpy array values are different \\(33\\.33333 %\\)
462
+ \\[left\\]: \\[á, à, ä\\]
463
+ \\[right\\]: \\[á, à, å\\]"""
464
+
465
+ with pytest.raises(AssertionError, match=msg):
466
+ tm.assert_almost_equal(np.array(["á", "à", "ä"]), np.array(["á", "à", "å"]))
467
+
468
+
469
+ def test_assert_almost_equal_timestamp():
470
+ a = np.array([Timestamp("2011-01-01"), Timestamp("2011-01-01")])
471
+ b = np.array([Timestamp("2011-01-01"), Timestamp("2011-01-02")])
472
+
473
+ msg = """numpy array are different
474
+
475
+ numpy array values are different \\(50\\.0 %\\)
476
+ \\[left\\]: \\[2011-01-01 00:00:00, 2011-01-01 00:00:00\\]
477
+ \\[right\\]: \\[2011-01-01 00:00:00, 2011-01-02 00:00:00\\]"""
478
+
479
+ with pytest.raises(AssertionError, match=msg):
480
+ tm.assert_almost_equal(a, b)
481
+
482
+
483
+ def test_assert_almost_equal_iterable_length_mismatch():
484
+ msg = """Iterable are different
485
+
486
+ Iterable length are different
487
+ \\[left\\]: 2
488
+ \\[right\\]: 3"""
489
+
490
+ with pytest.raises(AssertionError, match=msg):
491
+ tm.assert_almost_equal([1, 2], [3, 4, 5])
492
+
493
+
494
+ def test_assert_almost_equal_iterable_values_mismatch():
495
+ msg = """Iterable are different
496
+
497
+ Iterable values are different \\(50\\.0 %\\)
498
+ \\[left\\]: \\[1, 2\\]
499
+ \\[right\\]: \\[1, 3\\]"""
500
+
501
+ with pytest.raises(AssertionError, match=msg):
502
+ tm.assert_almost_equal([1, 2], [1, 3])
503
+
504
+
505
+ subarr = np.empty(2, dtype=object)
506
+ subarr[:] = [np.array([None, "b"], dtype=object), np.array(["c", "d"], dtype=object)]
507
+
508
+ NESTED_CASES = [
509
+ # nested array
510
+ (
511
+ np.array([np.array([50, 70, 90]), np.array([20, 30])], dtype=object),
512
+ np.array([np.array([50, 70, 90]), np.array([20, 30])], dtype=object),
513
+ ),
514
+ # >1 level of nesting
515
+ (
516
+ np.array(
517
+ [
518
+ np.array([np.array([50, 70]), np.array([90])], dtype=object),
519
+ np.array([np.array([20, 30])], dtype=object),
520
+ ],
521
+ dtype=object,
522
+ ),
523
+ np.array(
524
+ [
525
+ np.array([np.array([50, 70]), np.array([90])], dtype=object),
526
+ np.array([np.array([20, 30])], dtype=object),
527
+ ],
528
+ dtype=object,
529
+ ),
530
+ ),
531
+ # lists
532
+ (
533
+ np.array([[50, 70, 90], [20, 30]], dtype=object),
534
+ np.array([[50, 70, 90], [20, 30]], dtype=object),
535
+ ),
536
+ # mixed array/list
537
+ (
538
+ np.array([np.array([1, 2, 3]), np.array([4, 5])], dtype=object),
539
+ np.array([[1, 2, 3], [4, 5]], dtype=object),
540
+ ),
541
+ (
542
+ np.array(
543
+ [
544
+ np.array([np.array([1, 2, 3]), np.array([4, 5])], dtype=object),
545
+ np.array(
546
+ [np.array([6]), np.array([7, 8]), np.array([9])], dtype=object
547
+ ),
548
+ ],
549
+ dtype=object,
550
+ ),
551
+ np.array([[[1, 2, 3], [4, 5]], [[6], [7, 8], [9]]], dtype=object),
552
+ ),
553
+ # same-length lists
554
+ (
555
+ np.array([subarr, None], dtype=object),
556
+ np.array([[[None, "b"], ["c", "d"]], None], dtype=object),
557
+ ),
558
+ # dicts
559
+ (
560
+ np.array([{"f1": 1, "f2": np.array(["a", "b"], dtype=object)}], dtype=object),
561
+ np.array([{"f1": 1, "f2": np.array(["a", "b"], dtype=object)}], dtype=object),
562
+ ),
563
+ (
564
+ np.array([{"f1": 1, "f2": np.array(["a", "b"], dtype=object)}], dtype=object),
565
+ np.array([{"f1": 1, "f2": ["a", "b"]}], dtype=object),
566
+ ),
567
+ # array/list of dicts
568
+ (
569
+ np.array(
570
+ [
571
+ np.array(
572
+ [{"f1": 1, "f2": np.array(["a", "b"], dtype=object)}], dtype=object
573
+ ),
574
+ np.array([], dtype=object),
575
+ ],
576
+ dtype=object,
577
+ ),
578
+ np.array([[{"f1": 1, "f2": ["a", "b"]}], []], dtype=object),
579
+ ),
580
+ ]
581
+
582
+
583
+ @pytest.mark.filterwarnings("ignore:elementwise comparison failed:DeprecationWarning")
584
+ @pytest.mark.parametrize("a,b", NESTED_CASES)
585
+ def test_assert_almost_equal_array_nested(a, b):
586
+ _assert_almost_equal_both(a, b)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_attr_equal.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from types import SimpleNamespace
2
+
3
+ import pytest
4
+
5
+ from pandas.core.dtypes.common import is_float
6
+
7
+ import pandas._testing as tm
8
+
9
+
10
+ def test_assert_attr_equal(nulls_fixture):
11
+ obj = SimpleNamespace()
12
+ obj.na_value = nulls_fixture
13
+ tm.assert_attr_equal("na_value", obj, obj)
14
+
15
+
16
+ def test_assert_attr_equal_different_nulls(nulls_fixture, nulls_fixture2):
17
+ obj = SimpleNamespace()
18
+ obj.na_value = nulls_fixture
19
+
20
+ obj2 = SimpleNamespace()
21
+ obj2.na_value = nulls_fixture2
22
+
23
+ if nulls_fixture is nulls_fixture2:
24
+ tm.assert_attr_equal("na_value", obj, obj2)
25
+ elif is_float(nulls_fixture) and is_float(nulls_fixture2):
26
+ # we consider float("nan") and np.float64("nan") to be equivalent
27
+ tm.assert_attr_equal("na_value", obj, obj2)
28
+ elif type(nulls_fixture) is type(nulls_fixture2):
29
+ # e.g. Decimal("NaN")
30
+ tm.assert_attr_equal("na_value", obj, obj2)
31
+ else:
32
+ with pytest.raises(AssertionError, match='"na_value" are different'):
33
+ tm.assert_attr_equal("na_value", obj, obj2)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_categorical_equal.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import Categorical
4
+ import pandas._testing as tm
5
+
6
+
7
+ @pytest.mark.parametrize(
8
+ "c",
9
+ [Categorical([1, 2, 3, 4]), Categorical([1, 2, 3, 4], categories=[1, 2, 3, 4, 5])],
10
+ )
11
+ def test_categorical_equal(c):
12
+ tm.assert_categorical_equal(c, c)
13
+
14
+
15
+ @pytest.mark.parametrize("check_category_order", [True, False])
16
+ def test_categorical_equal_order_mismatch(check_category_order):
17
+ c1 = Categorical([1, 2, 3, 4], categories=[1, 2, 3, 4])
18
+ c2 = Categorical([1, 2, 3, 4], categories=[4, 3, 2, 1])
19
+ kwargs = {"check_category_order": check_category_order}
20
+
21
+ if check_category_order:
22
+ msg = """Categorical\\.categories are different
23
+
24
+ Categorical\\.categories values are different \\(100\\.0 %\\)
25
+ \\[left\\]: Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)
26
+ \\[right\\]: Index\\(\\[4, 3, 2, 1\\], dtype='int64'\\)"""
27
+ with pytest.raises(AssertionError, match=msg):
28
+ tm.assert_categorical_equal(c1, c2, **kwargs)
29
+ else:
30
+ tm.assert_categorical_equal(c1, c2, **kwargs)
31
+
32
+
33
+ def test_categorical_equal_categories_mismatch():
34
+ msg = """Categorical\\.categories are different
35
+
36
+ Categorical\\.categories values are different \\(25\\.0 %\\)
37
+ \\[left\\]: Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)
38
+ \\[right\\]: Index\\(\\[1, 2, 3, 5\\], dtype='int64'\\)"""
39
+
40
+ c1 = Categorical([1, 2, 3, 4])
41
+ c2 = Categorical([1, 2, 3, 5])
42
+
43
+ with pytest.raises(AssertionError, match=msg):
44
+ tm.assert_categorical_equal(c1, c2)
45
+
46
+
47
+ def test_categorical_equal_codes_mismatch():
48
+ categories = [1, 2, 3, 4]
49
+ msg = """Categorical\\.codes are different
50
+
51
+ Categorical\\.codes values are different \\(50\\.0 %\\)
52
+ \\[left\\]: \\[0, 1, 3, 2\\]
53
+ \\[right\\]: \\[0, 1, 2, 3\\]"""
54
+
55
+ c1 = Categorical([1, 2, 4, 3], categories=categories)
56
+ c2 = Categorical([1, 2, 3, 4], categories=categories)
57
+
58
+ with pytest.raises(AssertionError, match=msg):
59
+ tm.assert_categorical_equal(c1, c2)
60
+
61
+
62
+ def test_categorical_equal_ordered_mismatch():
63
+ data = [1, 2, 3, 4]
64
+ msg = """Categorical are different
65
+
66
+ Attribute "ordered" are different
67
+ \\[left\\]: False
68
+ \\[right\\]: True"""
69
+
70
+ c1 = Categorical(data, ordered=False)
71
+ c2 = Categorical(data, ordered=True)
72
+
73
+ with pytest.raises(AssertionError, match=msg):
74
+ tm.assert_categorical_equal(c1, c2)
75
+
76
+
77
+ @pytest.mark.parametrize("obj", ["index", "foo", "pandas"])
78
+ def test_categorical_equal_object_override(obj):
79
+ data = [1, 2, 3, 4]
80
+ msg = f"""{obj} are different
81
+
82
+ Attribute "ordered" are different
83
+ \\[left\\]: False
84
+ \\[right\\]: True"""
85
+
86
+ c1 = Categorical(data, ordered=False)
87
+ c2 = Categorical(data, ordered=True)
88
+
89
+ with pytest.raises(AssertionError, match=msg):
90
+ tm.assert_categorical_equal(c1, c2, obj=obj)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_extension_array_equal.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Timestamp,
6
+ array,
7
+ )
8
+ import pandas._testing as tm
9
+ from pandas.core.arrays.sparse import SparseArray
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ "kwargs",
14
+ [
15
+ {}, # Default is check_exact=False
16
+ {"check_exact": False},
17
+ {"check_exact": True},
18
+ ],
19
+ )
20
+ def test_assert_extension_array_equal_not_exact(kwargs):
21
+ # see gh-23709
22
+ arr1 = SparseArray([-0.17387645482451206, 0.3414148016424936])
23
+ arr2 = SparseArray([-0.17387645482451206, 0.3414148016424937])
24
+
25
+ if kwargs.get("check_exact", False):
26
+ msg = """\
27
+ ExtensionArray are different
28
+
29
+ ExtensionArray values are different \\(50\\.0 %\\)
30
+ \\[left\\]: \\[-0\\.17387645482.*, 0\\.341414801642.*\\]
31
+ \\[right\\]: \\[-0\\.17387645482.*, 0\\.341414801642.*\\]"""
32
+
33
+ with pytest.raises(AssertionError, match=msg):
34
+ tm.assert_extension_array_equal(arr1, arr2, **kwargs)
35
+ else:
36
+ tm.assert_extension_array_equal(arr1, arr2, **kwargs)
37
+
38
+
39
+ @pytest.mark.parametrize("decimals", range(10))
40
+ def test_assert_extension_array_equal_less_precise(decimals):
41
+ rtol = 0.5 * 10**-decimals
42
+ arr1 = SparseArray([0.5, 0.123456])
43
+ arr2 = SparseArray([0.5, 0.123457])
44
+
45
+ if decimals >= 5:
46
+ msg = """\
47
+ ExtensionArray are different
48
+
49
+ ExtensionArray values are different \\(50\\.0 %\\)
50
+ \\[left\\]: \\[0\\.5, 0\\.123456\\]
51
+ \\[right\\]: \\[0\\.5, 0\\.123457\\]"""
52
+
53
+ with pytest.raises(AssertionError, match=msg):
54
+ tm.assert_extension_array_equal(arr1, arr2, rtol=rtol)
55
+ else:
56
+ tm.assert_extension_array_equal(arr1, arr2, rtol=rtol)
57
+
58
+
59
+ def test_assert_extension_array_equal_dtype_mismatch(check_dtype):
60
+ end = 5
61
+ kwargs = {"check_dtype": check_dtype}
62
+
63
+ arr1 = SparseArray(np.arange(end, dtype="int64"))
64
+ arr2 = SparseArray(np.arange(end, dtype="int32"))
65
+
66
+ if check_dtype:
67
+ msg = """\
68
+ ExtensionArray are different
69
+
70
+ Attribute "dtype" are different
71
+ \\[left\\]: Sparse\\[int64, 0\\]
72
+ \\[right\\]: Sparse\\[int32, 0\\]"""
73
+
74
+ with pytest.raises(AssertionError, match=msg):
75
+ tm.assert_extension_array_equal(arr1, arr2, **kwargs)
76
+ else:
77
+ tm.assert_extension_array_equal(arr1, arr2, **kwargs)
78
+
79
+
80
+ def test_assert_extension_array_equal_missing_values():
81
+ arr1 = SparseArray([np.nan, 1, 2, np.nan])
82
+ arr2 = SparseArray([np.nan, 1, 2, 3])
83
+
84
+ msg = """\
85
+ ExtensionArray NA mask are different
86
+
87
+ ExtensionArray NA mask values are different \\(25\\.0 %\\)
88
+ \\[left\\]: \\[True, False, False, True\\]
89
+ \\[right\\]: \\[True, False, False, False\\]"""
90
+
91
+ with pytest.raises(AssertionError, match=msg):
92
+ tm.assert_extension_array_equal(arr1, arr2)
93
+
94
+
95
+ @pytest.mark.parametrize("side", ["left", "right"])
96
+ def test_assert_extension_array_equal_non_extension_array(side):
97
+ numpy_array = np.arange(5)
98
+ extension_array = SparseArray(numpy_array)
99
+
100
+ msg = f"{side} is not an ExtensionArray"
101
+ args = (
102
+ (numpy_array, extension_array)
103
+ if side == "left"
104
+ else (extension_array, numpy_array)
105
+ )
106
+
107
+ with pytest.raises(AssertionError, match=msg):
108
+ tm.assert_extension_array_equal(*args)
109
+
110
+
111
+ @pytest.mark.parametrize("right_dtype", ["Int32", "int64"])
112
+ def test_assert_extension_array_equal_ignore_dtype_mismatch(right_dtype):
113
+ # https://github.com/pandas-dev/pandas/issues/35715
114
+ left = array([1, 2, 3], dtype="Int64")
115
+ right = array([1, 2, 3], dtype=right_dtype)
116
+ tm.assert_extension_array_equal(left, right, check_dtype=False)
117
+
118
+
119
+ def test_assert_extension_array_equal_time_units():
120
+ # https://github.com/pandas-dev/pandas/issues/55730
121
+ timestamp = Timestamp("2023-11-04T12")
122
+ naive = array([timestamp], dtype="datetime64[ns]")
123
+ utc = array([timestamp], dtype="datetime64[ns, UTC]")
124
+
125
+ tm.assert_extension_array_equal(naive, utc, check_dtype=False)
126
+ tm.assert_extension_array_equal(utc, naive, check_dtype=False)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_frame_equal.py ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ import pandas as pd
4
+ from pandas import DataFrame
5
+ import pandas._testing as tm
6
+
7
+
8
+ @pytest.fixture(params=[True, False])
9
+ def by_blocks_fixture(request):
10
+ return request.param
11
+
12
+
13
+ @pytest.fixture(params=["DataFrame", "Series"])
14
+ def obj_fixture(request):
15
+ return request.param
16
+
17
+
18
+ def _assert_frame_equal_both(a, b, **kwargs):
19
+ """
20
+ Check that two DataFrame equal.
21
+
22
+ This check is performed commutatively.
23
+
24
+ Parameters
25
+ ----------
26
+ a : DataFrame
27
+ The first DataFrame to compare.
28
+ b : DataFrame
29
+ The second DataFrame to compare.
30
+ kwargs : dict
31
+ The arguments passed to `tm.assert_frame_equal`.
32
+ """
33
+ tm.assert_frame_equal(a, b, **kwargs)
34
+ tm.assert_frame_equal(b, a, **kwargs)
35
+
36
+
37
+ @pytest.mark.parametrize("check_like", [True, False])
38
+ def test_frame_equal_row_order_mismatch(check_like, obj_fixture):
39
+ df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])
40
+ df2 = DataFrame({"A": [3, 2, 1], "B": [6, 5, 4]}, index=["c", "b", "a"])
41
+
42
+ if not check_like: # Do not ignore row-column orderings.
43
+ msg = f"{obj_fixture}.index are different"
44
+ with pytest.raises(AssertionError, match=msg):
45
+ tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture)
46
+ else:
47
+ _assert_frame_equal_both(df1, df2, check_like=check_like, obj=obj_fixture)
48
+
49
+
50
+ @pytest.mark.parametrize(
51
+ "df1,df2",
52
+ [
53
+ (DataFrame({"A": [1, 2, 3]}), DataFrame({"A": [1, 2, 3, 4]})),
54
+ (DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}), DataFrame({"A": [1, 2, 3]})),
55
+ ],
56
+ )
57
+ def test_frame_equal_shape_mismatch(df1, df2, obj_fixture):
58
+ msg = f"{obj_fixture} are different"
59
+
60
+ with pytest.raises(AssertionError, match=msg):
61
+ tm.assert_frame_equal(df1, df2, obj=obj_fixture)
62
+
63
+
64
+ @pytest.mark.parametrize(
65
+ "df1,df2,msg",
66
+ [
67
+ # Index
68
+ (
69
+ DataFrame.from_records({"a": [1, 2], "c": ["l1", "l2"]}, index=["a"]),
70
+ DataFrame.from_records({"a": [1.0, 2.0], "c": ["l1", "l2"]}, index=["a"]),
71
+ "DataFrame\\.index are different",
72
+ ),
73
+ # MultiIndex
74
+ (
75
+ DataFrame.from_records(
76
+ {"a": [1, 2], "b": [2.1, 1.5], "c": ["l1", "l2"]}, index=["a", "b"]
77
+ ),
78
+ DataFrame.from_records(
79
+ {"a": [1.0, 2.0], "b": [2.1, 1.5], "c": ["l1", "l2"]}, index=["a", "b"]
80
+ ),
81
+ "MultiIndex level \\[0\\] are different",
82
+ ),
83
+ ],
84
+ )
85
+ def test_frame_equal_index_dtype_mismatch(df1, df2, msg, check_index_type):
86
+ kwargs = {"check_index_type": check_index_type}
87
+
88
+ if check_index_type:
89
+ with pytest.raises(AssertionError, match=msg):
90
+ tm.assert_frame_equal(df1, df2, **kwargs)
91
+ else:
92
+ tm.assert_frame_equal(df1, df2, **kwargs)
93
+
94
+
95
+ def test_empty_dtypes(check_dtype):
96
+ columns = ["col1", "col2"]
97
+ df1 = DataFrame(columns=columns)
98
+ df2 = DataFrame(columns=columns)
99
+
100
+ kwargs = {"check_dtype": check_dtype}
101
+ df1["col1"] = df1["col1"].astype("int64")
102
+
103
+ if check_dtype:
104
+ msg = r"Attributes of DataFrame\..* are different"
105
+ with pytest.raises(AssertionError, match=msg):
106
+ tm.assert_frame_equal(df1, df2, **kwargs)
107
+ else:
108
+ tm.assert_frame_equal(df1, df2, **kwargs)
109
+
110
+
111
+ @pytest.mark.parametrize("check_like", [True, False])
112
+ def test_frame_equal_index_mismatch(check_like, obj_fixture, using_infer_string):
113
+ if using_infer_string:
114
+ dtype = "string"
115
+ else:
116
+ dtype = "object"
117
+ msg = f"""{obj_fixture}\\.index are different
118
+
119
+ {obj_fixture}\\.index values are different \\(33\\.33333 %\\)
120
+ \\[left\\]: Index\\(\\['a', 'b', 'c'\\], dtype='{dtype}'\\)
121
+ \\[right\\]: Index\\(\\['a', 'b', 'd'\\], dtype='{dtype}'\\)
122
+ At positional index 2, first diff: c != d"""
123
+
124
+ df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])
125
+ df2 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "d"])
126
+
127
+ with pytest.raises(AssertionError, match=msg):
128
+ tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture)
129
+
130
+
131
+ @pytest.mark.parametrize("check_like", [True, False])
132
+ def test_frame_equal_columns_mismatch(check_like, obj_fixture, using_infer_string):
133
+ if using_infer_string:
134
+ dtype = "string"
135
+ else:
136
+ dtype = "object"
137
+ msg = f"""{obj_fixture}\\.columns are different
138
+
139
+ {obj_fixture}\\.columns values are different \\(50\\.0 %\\)
140
+ \\[left\\]: Index\\(\\['A', 'B'\\], dtype='{dtype}'\\)
141
+ \\[right\\]: Index\\(\\['A', 'b'\\], dtype='{dtype}'\\)"""
142
+
143
+ df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])
144
+ df2 = DataFrame({"A": [1, 2, 3], "b": [4, 5, 6]}, index=["a", "b", "c"])
145
+
146
+ with pytest.raises(AssertionError, match=msg):
147
+ tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture)
148
+
149
+
150
+ def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture):
151
+ obj = obj_fixture
152
+ msg = f"""{obj}\\.iloc\\[:, 1\\] \\(column name="B"\\) are different
153
+
154
+ {obj}\\.iloc\\[:, 1\\] \\(column name="B"\\) values are different \\(33\\.33333 %\\)
155
+ \\[index\\]: \\[0, 1, 2\\]
156
+ \\[left\\]: \\[4, 5, 6\\]
157
+ \\[right\\]: \\[4, 5, 7\\]"""
158
+
159
+ df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
160
+ df2 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 7]})
161
+
162
+ with pytest.raises(AssertionError, match=msg):
163
+ tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture)
164
+
165
+
166
+ @pytest.mark.parametrize(
167
+ "df1,df2,msg",
168
+ [
169
+ (
170
+ DataFrame({"A": ["á", "à", "ä"], "E": ["é", "è", "ë"]}),
171
+ DataFrame({"A": ["á", "à", "ä"], "E": ["é", "è", "e̊"]}),
172
+ """{obj}\\.iloc\\[:, 1\\] \\(column name="E"\\) are different
173
+
174
+ {obj}\\.iloc\\[:, 1\\] \\(column name="E"\\) values are different \\(33\\.33333 %\\)
175
+ \\[index\\]: \\[0, 1, 2\\]
176
+ \\[left\\]: \\[é, è, ë\\]
177
+ \\[right\\]: \\[é, è, e̊\\]""",
178
+ ),
179
+ (
180
+ DataFrame({"A": ["á", "à", "ä"], "E": ["é", "è", "ë"]}),
181
+ DataFrame({"A": ["a", "a", "a"], "E": ["e", "e", "e"]}),
182
+ """{obj}\\.iloc\\[:, 0\\] \\(column name="A"\\) are different
183
+
184
+ {obj}\\.iloc\\[:, 0\\] \\(column name="A"\\) values are different \\(100\\.0 %\\)
185
+ \\[index\\]: \\[0, 1, 2\\]
186
+ \\[left\\]: \\[á, à, ä\\]
187
+ \\[right\\]: \\[a, a, a\\]""",
188
+ ),
189
+ ],
190
+ )
191
+ def test_frame_equal_unicode(df1, df2, msg, by_blocks_fixture, obj_fixture):
192
+ # see gh-20503
193
+ #
194
+ # Test ensures that `tm.assert_frame_equals` raises the right exception
195
+ # when comparing DataFrames containing differing unicode objects.
196
+ msg = msg.format(obj=obj_fixture)
197
+ with pytest.raises(AssertionError, match=msg):
198
+ tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture)
199
+
200
+
201
+ def test_assert_frame_equal_extension_dtype_mismatch():
202
+ # https://github.com/pandas-dev/pandas/issues/32747
203
+ left = DataFrame({"a": [1, 2, 3]}, dtype="Int64")
204
+ right = left.astype(int)
205
+
206
+ msg = (
207
+ "Attributes of DataFrame\\.iloc\\[:, 0\\] "
208
+ '\\(column name="a"\\) are different\n\n'
209
+ 'Attribute "dtype" are different\n'
210
+ "\\[left\\]: Int64\n"
211
+ "\\[right\\]: int[32|64]"
212
+ )
213
+
214
+ tm.assert_frame_equal(left, right, check_dtype=False)
215
+
216
+ with pytest.raises(AssertionError, match=msg):
217
+ tm.assert_frame_equal(left, right, check_dtype=True)
218
+
219
+
220
+ def test_assert_frame_equal_interval_dtype_mismatch():
221
+ # https://github.com/pandas-dev/pandas/issues/32747
222
+ left = DataFrame({"a": [pd.Interval(0, 1)]}, dtype="interval")
223
+ right = left.astype(object)
224
+
225
+ msg = (
226
+ "Attributes of DataFrame\\.iloc\\[:, 0\\] "
227
+ '\\(column name="a"\\) are different\n\n'
228
+ 'Attribute "dtype" are different\n'
229
+ "\\[left\\]: interval\\[int64, right\\]\n"
230
+ "\\[right\\]: object"
231
+ )
232
+
233
+ tm.assert_frame_equal(left, right, check_dtype=False)
234
+
235
+ with pytest.raises(AssertionError, match=msg):
236
+ tm.assert_frame_equal(left, right, check_dtype=True)
237
+
238
+
239
+ def test_assert_frame_equal_ignore_extension_dtype_mismatch():
240
+ # https://github.com/pandas-dev/pandas/issues/35715
241
+ left = DataFrame({"a": [1, 2, 3]}, dtype="Int64")
242
+ right = DataFrame({"a": [1, 2, 3]}, dtype="Int32")
243
+ tm.assert_frame_equal(left, right, check_dtype=False)
244
+
245
+
246
+ def test_assert_frame_equal_ignore_extension_dtype_mismatch_cross_class():
247
+ # https://github.com/pandas-dev/pandas/issues/35715
248
+ left = DataFrame({"a": [1, 2, 3]}, dtype="Int64")
249
+ right = DataFrame({"a": [1, 2, 3]}, dtype="int64")
250
+ tm.assert_frame_equal(left, right, check_dtype=False)
251
+
252
+
253
+ @pytest.mark.parametrize(
254
+ "dtype",
255
+ [
256
+ ("timedelta64[ns]"),
257
+ ("datetime64[ns, UTC]"),
258
+ ("Period[D]"),
259
+ ],
260
+ )
261
+ def test_assert_frame_equal_datetime_like_dtype_mismatch(dtype):
262
+ df1 = DataFrame({"a": []}, dtype=dtype)
263
+ df2 = DataFrame({"a": []})
264
+ tm.assert_frame_equal(df1, df2, check_dtype=False)
265
+
266
+
267
+ def test_allows_duplicate_labels():
268
+ left = DataFrame()
269
+ right = DataFrame().set_flags(allows_duplicate_labels=False)
270
+ tm.assert_frame_equal(left, left)
271
+ tm.assert_frame_equal(right, right)
272
+ tm.assert_frame_equal(left, right, check_flags=False)
273
+ tm.assert_frame_equal(right, left, check_flags=False)
274
+
275
+ with pytest.raises(AssertionError, match="<Flags"):
276
+ tm.assert_frame_equal(left, right)
277
+
278
+ with pytest.raises(AssertionError, match="<Flags"):
279
+ tm.assert_frame_equal(left, right)
280
+
281
+
282
+ def test_assert_frame_equal_columns_mixed_dtype():
283
+ # GH#39168
284
+ df = DataFrame([[0, 1, 2]], columns=["foo", "bar", 42], index=[1, "test", 2])
285
+ tm.assert_frame_equal(df, df, check_like=True)
286
+
287
+
288
+ def test_frame_equal_extension_dtype(frame_or_series, any_numeric_ea_dtype):
289
+ # GH#39410
290
+ obj = frame_or_series([1, 2], dtype=any_numeric_ea_dtype)
291
+ tm.assert_equal(obj, obj, check_exact=True)
292
+
293
+
294
+ @pytest.mark.parametrize("indexer", [(0, 1), (1, 0)])
295
+ def test_frame_equal_mixed_dtypes(frame_or_series, any_numeric_ea_dtype, indexer):
296
+ dtypes = (any_numeric_ea_dtype, "int64")
297
+ obj1 = frame_or_series([1, 2], dtype=dtypes[indexer[0]])
298
+ obj2 = frame_or_series([1, 2], dtype=dtypes[indexer[1]])
299
+ tm.assert_equal(obj1, obj2, check_exact=True, check_dtype=False)
300
+
301
+
302
+ def test_assert_frame_equal_check_like_different_indexes():
303
+ # GH#39739
304
+ df1 = DataFrame(index=pd.Index([], dtype="object"))
305
+ df2 = DataFrame(index=pd.RangeIndex(start=0, stop=0, step=1))
306
+ with pytest.raises(AssertionError, match="DataFrame.index are different"):
307
+ tm.assert_frame_equal(df1, df2, check_like=True)
308
+
309
+
310
+ def test_assert_frame_equal_checking_allow_dups_flag():
311
+ # GH#45554
312
+ left = DataFrame([[1, 2], [3, 4]])
313
+ left.flags.allows_duplicate_labels = False
314
+
315
+ right = DataFrame([[1, 2], [3, 4]])
316
+ right.flags.allows_duplicate_labels = True
317
+ tm.assert_frame_equal(left, right, check_flags=False)
318
+
319
+ with pytest.raises(AssertionError, match="allows_duplicate_labels"):
320
+ tm.assert_frame_equal(left, right, check_flags=True)
321
+
322
+
323
+ def test_assert_frame_equal_check_like_categorical_midx():
324
+ # GH#48975
325
+ left = DataFrame(
326
+ [[1], [2], [3]],
327
+ index=pd.MultiIndex.from_arrays(
328
+ [
329
+ pd.Categorical(["a", "b", "c"]),
330
+ pd.Categorical(["a", "b", "c"]),
331
+ ]
332
+ ),
333
+ )
334
+ right = DataFrame(
335
+ [[3], [2], [1]],
336
+ index=pd.MultiIndex.from_arrays(
337
+ [
338
+ pd.Categorical(["c", "b", "a"]),
339
+ pd.Categorical(["c", "b", "a"]),
340
+ ]
341
+ ),
342
+ )
343
+ tm.assert_frame_equal(left, right, check_like=True)
344
+
345
+
346
+ def test_assert_frame_equal_ea_column_definition_in_exception_mask():
347
+ # GH#50323
348
+ df1 = DataFrame({"a": pd.Series([pd.NA, 1], dtype="Int64")})
349
+ df2 = DataFrame({"a": pd.Series([1, 1], dtype="Int64")})
350
+
351
+ msg = r'DataFrame.iloc\[:, 0\] \(column name="a"\) NA mask values are different'
352
+ with pytest.raises(AssertionError, match=msg):
353
+ tm.assert_frame_equal(df1, df2)
354
+
355
+
356
+ def test_assert_frame_equal_ea_column_definition_in_exception():
357
+ # GH#50323
358
+ df1 = DataFrame({"a": pd.Series([pd.NA, 1], dtype="Int64")})
359
+ df2 = DataFrame({"a": pd.Series([pd.NA, 2], dtype="Int64")})
360
+
361
+ msg = r'DataFrame.iloc\[:, 0\] \(column name="a"\) values are different'
362
+ with pytest.raises(AssertionError, match=msg):
363
+ tm.assert_frame_equal(df1, df2)
364
+
365
+ with pytest.raises(AssertionError, match=msg):
366
+ tm.assert_frame_equal(df1, df2, check_exact=True)
367
+
368
+
369
+ def test_assert_frame_equal_ts_column():
370
+ # GH#50323
371
+ df1 = DataFrame({"a": [pd.Timestamp("2019-12-31"), pd.Timestamp("2020-12-31")]})
372
+ df2 = DataFrame({"a": [pd.Timestamp("2020-12-31"), pd.Timestamp("2020-12-31")]})
373
+
374
+ msg = r'DataFrame.iloc\[:, 0\] \(column name="a"\) values are different'
375
+ with pytest.raises(AssertionError, match=msg):
376
+ tm.assert_frame_equal(df1, df2)
377
+
378
+
379
+ def test_assert_frame_equal_set():
380
+ # GH#51727
381
+ df1 = DataFrame({"set_column": [{1, 2, 3}, {4, 5, 6}]})
382
+ df2 = DataFrame({"set_column": [{1, 2, 3}, {4, 5, 6}]})
383
+ tm.assert_frame_equal(df1, df2)
384
+
385
+
386
+ def test_assert_frame_equal_set_mismatch():
387
+ # GH#51727
388
+ df1 = DataFrame({"set_column": [{1, 2, 3}, {4, 5, 6}]})
389
+ df2 = DataFrame({"set_column": [{1, 2, 3}, {4, 5, 7}]})
390
+
391
+ msg = r'DataFrame.iloc\[:, 0\] \(column name="set_column"\) values are different'
392
+ with pytest.raises(AssertionError, match=msg):
393
+ tm.assert_frame_equal(df1, df2)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_index_equal.py ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ NA,
6
+ Categorical,
7
+ CategoricalIndex,
8
+ Index,
9
+ MultiIndex,
10
+ NaT,
11
+ RangeIndex,
12
+ )
13
+ import pandas._testing as tm
14
+
15
+
16
+ def test_index_equal_levels_mismatch():
17
+ msg = """Index are different
18
+
19
+ Index levels are different
20
+ \\[left\\]: 1, Index\\(\\[1, 2, 3\\], dtype='int64'\\)
21
+ \\[right\\]: 2, MultiIndex\\(\\[\\('A', 1\\),
22
+ \\('A', 2\\),
23
+ \\('B', 3\\),
24
+ \\('B', 4\\)\\],
25
+ \\)"""
26
+
27
+ idx1 = Index([1, 2, 3])
28
+ idx2 = MultiIndex.from_tuples([("A", 1), ("A", 2), ("B", 3), ("B", 4)])
29
+
30
+ with pytest.raises(AssertionError, match=msg):
31
+ tm.assert_index_equal(idx1, idx2, exact=False)
32
+
33
+
34
+ def test_index_equal_values_mismatch(check_exact):
35
+ msg = """MultiIndex level \\[1\\] are different
36
+
37
+ MultiIndex level \\[1\\] values are different \\(25\\.0 %\\)
38
+ \\[left\\]: Index\\(\\[2, 2, 3, 4\\], dtype='int64'\\)
39
+ \\[right\\]: Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)"""
40
+
41
+ idx1 = MultiIndex.from_tuples([("A", 2), ("A", 2), ("B", 3), ("B", 4)])
42
+ idx2 = MultiIndex.from_tuples([("A", 1), ("A", 2), ("B", 3), ("B", 4)])
43
+
44
+ with pytest.raises(AssertionError, match=msg):
45
+ tm.assert_index_equal(idx1, idx2, check_exact=check_exact)
46
+
47
+
48
+ def test_index_equal_length_mismatch(check_exact):
49
+ msg = """Index are different
50
+
51
+ Index length are different
52
+ \\[left\\]: 3, Index\\(\\[1, 2, 3\\], dtype='int64'\\)
53
+ \\[right\\]: 4, Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)"""
54
+
55
+ idx1 = Index([1, 2, 3])
56
+ idx2 = Index([1, 2, 3, 4])
57
+
58
+ with pytest.raises(AssertionError, match=msg):
59
+ tm.assert_index_equal(idx1, idx2, check_exact=check_exact)
60
+
61
+
62
+ @pytest.mark.parametrize("exact", [False, "equiv"])
63
+ def test_index_equal_class(exact):
64
+ idx1 = Index([0, 1, 2])
65
+ idx2 = RangeIndex(3)
66
+
67
+ tm.assert_index_equal(idx1, idx2, exact=exact)
68
+
69
+
70
+ def test_int_float_index_equal_class_mismatch(check_exact):
71
+ msg = """Index are different
72
+
73
+ Attribute "inferred_type" are different
74
+ \\[left\\]: integer
75
+ \\[right\\]: floating"""
76
+
77
+ idx1 = Index([1, 2, 3])
78
+ idx2 = Index([1, 2, 3], dtype=np.float64)
79
+
80
+ with pytest.raises(AssertionError, match=msg):
81
+ tm.assert_index_equal(idx1, idx2, exact=True, check_exact=check_exact)
82
+
83
+
84
+ def test_range_index_equal_class_mismatch(check_exact):
85
+ msg = """Index are different
86
+
87
+ Index classes are different
88
+ \\[left\\]: Index\\(\\[1, 2, 3\\], dtype='int64'\\)
89
+ \\[right\\]: """
90
+
91
+ idx1 = Index([1, 2, 3])
92
+ idx2 = RangeIndex(range(3))
93
+
94
+ with pytest.raises(AssertionError, match=msg):
95
+ tm.assert_index_equal(idx1, idx2, exact=True, check_exact=check_exact)
96
+
97
+
98
+ def test_index_equal_values_close(check_exact):
99
+ idx1 = Index([1, 2, 3.0])
100
+ idx2 = Index([1, 2, 3.0000000001])
101
+
102
+ if check_exact:
103
+ msg = """Index are different
104
+
105
+ Index values are different \\(33\\.33333 %\\)
106
+ \\[left\\]: Index\\(\\[1.0, 2.0, 3.0], dtype='float64'\\)
107
+ \\[right\\]: Index\\(\\[1.0, 2.0, 3.0000000001\\], dtype='float64'\\)"""
108
+
109
+ with pytest.raises(AssertionError, match=msg):
110
+ tm.assert_index_equal(idx1, idx2, check_exact=check_exact)
111
+ else:
112
+ tm.assert_index_equal(idx1, idx2, check_exact=check_exact)
113
+
114
+
115
+ def test_index_equal_values_less_close(check_exact, rtol):
116
+ idx1 = Index([1, 2, 3.0])
117
+ idx2 = Index([1, 2, 3.0001])
118
+ kwargs = {"check_exact": check_exact, "rtol": rtol}
119
+
120
+ if check_exact or rtol < 0.5e-3:
121
+ msg = """Index are different
122
+
123
+ Index values are different \\(33\\.33333 %\\)
124
+ \\[left\\]: Index\\(\\[1.0, 2.0, 3.0], dtype='float64'\\)
125
+ \\[right\\]: Index\\(\\[1.0, 2.0, 3.0001\\], dtype='float64'\\)"""
126
+
127
+ with pytest.raises(AssertionError, match=msg):
128
+ tm.assert_index_equal(idx1, idx2, **kwargs)
129
+ else:
130
+ tm.assert_index_equal(idx1, idx2, **kwargs)
131
+
132
+
133
+ def test_index_equal_values_too_far(check_exact, rtol):
134
+ idx1 = Index([1, 2, 3])
135
+ idx2 = Index([1, 2, 4])
136
+ kwargs = {"check_exact": check_exact, "rtol": rtol}
137
+
138
+ msg = """Index are different
139
+
140
+ Index values are different \\(33\\.33333 %\\)
141
+ \\[left\\]: Index\\(\\[1, 2, 3\\], dtype='int64'\\)
142
+ \\[right\\]: Index\\(\\[1, 2, 4\\], dtype='int64'\\)"""
143
+
144
+ with pytest.raises(AssertionError, match=msg):
145
+ tm.assert_index_equal(idx1, idx2, **kwargs)
146
+
147
+
148
+ @pytest.mark.parametrize("check_order", [True, False])
149
+ def test_index_equal_value_order_mismatch(check_exact, rtol, check_order):
150
+ idx1 = Index([1, 2, 3])
151
+ idx2 = Index([3, 2, 1])
152
+
153
+ msg = """Index are different
154
+
155
+ Index values are different \\(66\\.66667 %\\)
156
+ \\[left\\]: Index\\(\\[1, 2, 3\\], dtype='int64'\\)
157
+ \\[right\\]: Index\\(\\[3, 2, 1\\], dtype='int64'\\)"""
158
+
159
+ if check_order:
160
+ with pytest.raises(AssertionError, match=msg):
161
+ tm.assert_index_equal(
162
+ idx1, idx2, check_exact=check_exact, rtol=rtol, check_order=True
163
+ )
164
+ else:
165
+ tm.assert_index_equal(
166
+ idx1, idx2, check_exact=check_exact, rtol=rtol, check_order=False
167
+ )
168
+
169
+
170
+ def test_index_equal_level_values_mismatch(check_exact, rtol):
171
+ idx1 = MultiIndex.from_tuples([("A", 2), ("A", 2), ("B", 3), ("B", 4)])
172
+ idx2 = MultiIndex.from_tuples([("A", 1), ("A", 2), ("B", 3), ("B", 4)])
173
+ kwargs = {"check_exact": check_exact, "rtol": rtol}
174
+
175
+ msg = """MultiIndex level \\[1\\] are different
176
+
177
+ MultiIndex level \\[1\\] values are different \\(25\\.0 %\\)
178
+ \\[left\\]: Index\\(\\[2, 2, 3, 4\\], dtype='int64'\\)
179
+ \\[right\\]: Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)"""
180
+
181
+ with pytest.raises(AssertionError, match=msg):
182
+ tm.assert_index_equal(idx1, idx2, **kwargs)
183
+
184
+
185
+ @pytest.mark.parametrize(
186
+ "name1,name2",
187
+ [(None, "x"), ("x", "x"), (np.nan, np.nan), (NaT, NaT), (np.nan, NaT)],
188
+ )
189
+ def test_index_equal_names(name1, name2):
190
+ idx1 = Index([1, 2, 3], name=name1)
191
+ idx2 = Index([1, 2, 3], name=name2)
192
+
193
+ if name1 == name2 or name1 is name2:
194
+ tm.assert_index_equal(idx1, idx2)
195
+ else:
196
+ name1 = "'x'" if name1 == "x" else name1
197
+ name2 = "'x'" if name2 == "x" else name2
198
+ msg = f"""Index are different
199
+
200
+ Attribute "names" are different
201
+ \\[left\\]: \\[{name1}\\]
202
+ \\[right\\]: \\[{name2}\\]"""
203
+
204
+ with pytest.raises(AssertionError, match=msg):
205
+ tm.assert_index_equal(idx1, idx2)
206
+
207
+
208
+ def test_index_equal_category_mismatch(check_categorical, using_infer_string):
209
+ if using_infer_string:
210
+ dtype = "string"
211
+ else:
212
+ dtype = "object"
213
+ msg = f"""Index are different
214
+
215
+ Attribute "dtype" are different
216
+ \\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False, \
217
+ categories_dtype={dtype}\\)
218
+ \\[right\\]: CategoricalDtype\\(categories=\\['a', 'b', 'c'\\], \
219
+ ordered=False, categories_dtype={dtype}\\)"""
220
+
221
+ idx1 = Index(Categorical(["a", "b"]))
222
+ idx2 = Index(Categorical(["a", "b"], categories=["a", "b", "c"]))
223
+
224
+ if check_categorical:
225
+ with pytest.raises(AssertionError, match=msg):
226
+ tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical)
227
+ else:
228
+ tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical)
229
+
230
+
231
+ @pytest.mark.parametrize("exact", [False, True])
232
+ def test_index_equal_range_categories(check_categorical, exact):
233
+ # GH41263
234
+ msg = """\
235
+ Index are different
236
+
237
+ Index classes are different
238
+ \\[left\\]: RangeIndex\\(start=0, stop=10, step=1\\)
239
+ \\[right\\]: Index\\(\\[0, 1, 2, 3, 4, 5, 6, 7, 8, 9\\], dtype='int64'\\)"""
240
+
241
+ rcat = CategoricalIndex(RangeIndex(10))
242
+ icat = CategoricalIndex(list(range(10)))
243
+
244
+ if check_categorical and exact:
245
+ with pytest.raises(AssertionError, match=msg):
246
+ tm.assert_index_equal(rcat, icat, check_categorical=True, exact=True)
247
+ else:
248
+ tm.assert_index_equal(
249
+ rcat, icat, check_categorical=check_categorical, exact=exact
250
+ )
251
+
252
+
253
+ def test_assert_index_equal_different_inferred_types():
254
+ # GH#31884
255
+ msg = """\
256
+ Index are different
257
+
258
+ Attribute "inferred_type" are different
259
+ \\[left\\]: mixed
260
+ \\[right\\]: datetime"""
261
+
262
+ idx1 = Index([NA, np.datetime64("nat")])
263
+ idx2 = Index([NA, NaT])
264
+ with pytest.raises(AssertionError, match=msg):
265
+ tm.assert_index_equal(idx1, idx2)
266
+
267
+
268
+ def test_assert_index_equal_different_names_check_order_false():
269
+ # GH#47328
270
+ idx1 = Index([1, 3], name="a")
271
+ idx2 = Index([3, 1], name="b")
272
+ with pytest.raises(AssertionError, match='"names" are different'):
273
+ tm.assert_index_equal(idx1, idx2, check_order=False, check_names=True)
274
+
275
+
276
+ def test_assert_index_equal_mixed_dtype():
277
+ # GH#39168
278
+ idx = Index(["foo", "bar", 42])
279
+ tm.assert_index_equal(idx, idx, check_order=False)
280
+
281
+
282
+ def test_assert_index_equal_ea_dtype_order_false(any_numeric_ea_dtype):
283
+ # GH#47207
284
+ idx1 = Index([1, 3], dtype=any_numeric_ea_dtype)
285
+ idx2 = Index([3, 1], dtype=any_numeric_ea_dtype)
286
+ tm.assert_index_equal(idx1, idx2, check_order=False)
287
+
288
+
289
+ def test_assert_index_equal_object_ints_order_false():
290
+ # GH#47207
291
+ idx1 = Index([1, 3], dtype="object")
292
+ idx2 = Index([3, 1], dtype="object")
293
+ tm.assert_index_equal(idx1, idx2, check_order=False)
294
+
295
+
296
+ @pytest.mark.parametrize("check_categorical", [True, False])
297
+ @pytest.mark.parametrize("check_names", [True, False])
298
+ def test_assert_ea_index_equal_non_matching_na(check_names, check_categorical):
299
+ # GH#48608
300
+ idx1 = Index([1, 2], dtype="Int64")
301
+ idx2 = Index([1, NA], dtype="Int64")
302
+ with pytest.raises(AssertionError, match="50.0 %"):
303
+ tm.assert_index_equal(
304
+ idx1, idx2, check_names=check_names, check_categorical=check_categorical
305
+ )
306
+
307
+
308
+ @pytest.mark.parametrize("check_categorical", [True, False])
309
+ def test_assert_multi_index_dtype_check_categorical(check_categorical):
310
+ # GH#52126
311
+ idx1 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.uint64))])
312
+ idx2 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.int64))])
313
+ if check_categorical:
314
+ with pytest.raises(
315
+ AssertionError, match=r"^MultiIndex level \[0\] are different"
316
+ ):
317
+ tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical)
318
+ else:
319
+ tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_interval_array_equal.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import interval_range
4
+ import pandas._testing as tm
5
+
6
+
7
+ @pytest.mark.parametrize(
8
+ "kwargs",
9
+ [
10
+ {"start": 0, "periods": 4},
11
+ {"start": 1, "periods": 5},
12
+ {"start": 5, "end": 10, "closed": "left"},
13
+ ],
14
+ )
15
+ def test_interval_array_equal(kwargs):
16
+ arr = interval_range(**kwargs).values
17
+ tm.assert_interval_array_equal(arr, arr)
18
+
19
+
20
+ def test_interval_array_equal_closed_mismatch():
21
+ kwargs = {"start": 0, "periods": 5}
22
+ arr1 = interval_range(closed="left", **kwargs).values
23
+ arr2 = interval_range(closed="right", **kwargs).values
24
+
25
+ msg = """\
26
+ IntervalArray are different
27
+
28
+ Attribute "closed" are different
29
+ \\[left\\]: left
30
+ \\[right\\]: right"""
31
+
32
+ with pytest.raises(AssertionError, match=msg):
33
+ tm.assert_interval_array_equal(arr1, arr2)
34
+
35
+
36
+ def test_interval_array_equal_periods_mismatch():
37
+ kwargs = {"start": 0}
38
+ arr1 = interval_range(periods=5, **kwargs).values
39
+ arr2 = interval_range(periods=6, **kwargs).values
40
+
41
+ msg = """\
42
+ IntervalArray.left are different
43
+
44
+ IntervalArray.left shapes are different
45
+ \\[left\\]: \\(5,\\)
46
+ \\[right\\]: \\(6,\\)"""
47
+
48
+ with pytest.raises(AssertionError, match=msg):
49
+ tm.assert_interval_array_equal(arr1, arr2)
50
+
51
+
52
+ def test_interval_array_equal_end_mismatch():
53
+ kwargs = {"start": 0, "periods": 5}
54
+ arr1 = interval_range(end=10, **kwargs).values
55
+ arr2 = interval_range(end=20, **kwargs).values
56
+
57
+ msg = """\
58
+ IntervalArray.left are different
59
+
60
+ IntervalArray.left values are different \\(80.0 %\\)
61
+ \\[left\\]: \\[0, 2, 4, 6, 8\\]
62
+ \\[right\\]: \\[0, 4, 8, 12, 16\\]"""
63
+
64
+ with pytest.raises(AssertionError, match=msg):
65
+ tm.assert_interval_array_equal(arr1, arr2)
66
+
67
+
68
+ def test_interval_array_equal_start_mismatch():
69
+ kwargs = {"periods": 4}
70
+ arr1 = interval_range(start=0, **kwargs).values
71
+ arr2 = interval_range(start=1, **kwargs).values
72
+
73
+ msg = """\
74
+ IntervalArray.left are different
75
+
76
+ IntervalArray.left values are different \\(100.0 %\\)
77
+ \\[left\\]: \\[0, 1, 2, 3\\]
78
+ \\[right\\]: \\[1, 2, 3, 4\\]"""
79
+
80
+ with pytest.raises(AssertionError, match=msg):
81
+ tm.assert_interval_array_equal(arr1, arr2)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_numpy_array_equal.py ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import copy
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ import pandas as pd
7
+ from pandas import Timestamp
8
+ import pandas._testing as tm
9
+
10
+
11
+ def test_assert_numpy_array_equal_shape_mismatch():
12
+ msg = """numpy array are different
13
+
14
+ numpy array shapes are different
15
+ \\[left\\]: \\(2L*,\\)
16
+ \\[right\\]: \\(3L*,\\)"""
17
+
18
+ with pytest.raises(AssertionError, match=msg):
19
+ tm.assert_numpy_array_equal(np.array([1, 2]), np.array([3, 4, 5]))
20
+
21
+
22
+ def test_assert_numpy_array_equal_bad_type():
23
+ expected = "Expected type"
24
+
25
+ with pytest.raises(AssertionError, match=expected):
26
+ tm.assert_numpy_array_equal(1, 2)
27
+
28
+
29
+ @pytest.mark.parametrize(
30
+ "a,b,klass1,klass2",
31
+ [(np.array([1]), 1, "ndarray", "int"), (1, np.array([1]), "int", "ndarray")],
32
+ )
33
+ def test_assert_numpy_array_equal_class_mismatch(a, b, klass1, klass2):
34
+ msg = f"""numpy array are different
35
+
36
+ numpy array classes are different
37
+ \\[left\\]: {klass1}
38
+ \\[right\\]: {klass2}"""
39
+
40
+ with pytest.raises(AssertionError, match=msg):
41
+ tm.assert_numpy_array_equal(a, b)
42
+
43
+
44
+ def test_assert_numpy_array_equal_value_mismatch1():
45
+ msg = """numpy array are different
46
+
47
+ numpy array values are different \\(66\\.66667 %\\)
48
+ \\[left\\]: \\[nan, 2\\.0, 3\\.0\\]
49
+ \\[right\\]: \\[1\\.0, nan, 3\\.0\\]"""
50
+
51
+ with pytest.raises(AssertionError, match=msg):
52
+ tm.assert_numpy_array_equal(np.array([np.nan, 2, 3]), np.array([1, np.nan, 3]))
53
+
54
+
55
+ def test_assert_numpy_array_equal_value_mismatch2():
56
+ msg = """numpy array are different
57
+
58
+ numpy array values are different \\(50\\.0 %\\)
59
+ \\[left\\]: \\[1, 2\\]
60
+ \\[right\\]: \\[1, 3\\]"""
61
+
62
+ with pytest.raises(AssertionError, match=msg):
63
+ tm.assert_numpy_array_equal(np.array([1, 2]), np.array([1, 3]))
64
+
65
+
66
+ def test_assert_numpy_array_equal_value_mismatch3():
67
+ msg = """numpy array are different
68
+
69
+ numpy array values are different \\(16\\.66667 %\\)
70
+ \\[left\\]: \\[\\[1, 2\\], \\[3, 4\\], \\[5, 6\\]\\]
71
+ \\[right\\]: \\[\\[1, 3\\], \\[3, 4\\], \\[5, 6\\]\\]"""
72
+
73
+ with pytest.raises(AssertionError, match=msg):
74
+ tm.assert_numpy_array_equal(
75
+ np.array([[1, 2], [3, 4], [5, 6]]), np.array([[1, 3], [3, 4], [5, 6]])
76
+ )
77
+
78
+
79
+ def test_assert_numpy_array_equal_value_mismatch4():
80
+ msg = """numpy array are different
81
+
82
+ numpy array values are different \\(50\\.0 %\\)
83
+ \\[left\\]: \\[1\\.1, 2\\.000001\\]
84
+ \\[right\\]: \\[1\\.1, 2.0\\]"""
85
+
86
+ with pytest.raises(AssertionError, match=msg):
87
+ tm.assert_numpy_array_equal(np.array([1.1, 2.000001]), np.array([1.1, 2.0]))
88
+
89
+
90
+ def test_assert_numpy_array_equal_value_mismatch5():
91
+ msg = """numpy array are different
92
+
93
+ numpy array values are different \\(16\\.66667 %\\)
94
+ \\[left\\]: \\[\\[1, 2\\], \\[3, 4\\], \\[5, 6\\]\\]
95
+ \\[right\\]: \\[\\[1, 3\\], \\[3, 4\\], \\[5, 6\\]\\]"""
96
+
97
+ with pytest.raises(AssertionError, match=msg):
98
+ tm.assert_numpy_array_equal(
99
+ np.array([[1, 2], [3, 4], [5, 6]]), np.array([[1, 3], [3, 4], [5, 6]])
100
+ )
101
+
102
+
103
+ def test_assert_numpy_array_equal_value_mismatch6():
104
+ msg = """numpy array are different
105
+
106
+ numpy array values are different \\(25\\.0 %\\)
107
+ \\[left\\]: \\[\\[1, 2\\], \\[3, 4\\]\\]
108
+ \\[right\\]: \\[\\[1, 3\\], \\[3, 4\\]\\]"""
109
+
110
+ with pytest.raises(AssertionError, match=msg):
111
+ tm.assert_numpy_array_equal(
112
+ np.array([[1, 2], [3, 4]]), np.array([[1, 3], [3, 4]])
113
+ )
114
+
115
+
116
+ def test_assert_numpy_array_equal_shape_mismatch_override():
117
+ msg = """Index are different
118
+
119
+ Index shapes are different
120
+ \\[left\\]: \\(2L*,\\)
121
+ \\[right\\]: \\(3L*,\\)"""
122
+
123
+ with pytest.raises(AssertionError, match=msg):
124
+ tm.assert_numpy_array_equal(np.array([1, 2]), np.array([3, 4, 5]), obj="Index")
125
+
126
+
127
+ def test_numpy_array_equal_unicode():
128
+ # see gh-20503
129
+ #
130
+ # Test ensures that `tm.assert_numpy_array_equals` raises the right
131
+ # exception when comparing np.arrays containing differing unicode objects.
132
+ msg = """numpy array are different
133
+
134
+ numpy array values are different \\(33\\.33333 %\\)
135
+ \\[left\\]: \\[á, à, ä\\]
136
+ \\[right\\]: \\[á, à, å\\]"""
137
+
138
+ with pytest.raises(AssertionError, match=msg):
139
+ tm.assert_numpy_array_equal(
140
+ np.array(["á", "à", "ä"]), np.array(["á", "à", "å"])
141
+ )
142
+
143
+
144
+ def test_numpy_array_equal_object():
145
+ a = np.array([Timestamp("2011-01-01"), Timestamp("2011-01-01")])
146
+ b = np.array([Timestamp("2011-01-01"), Timestamp("2011-01-02")])
147
+
148
+ msg = """numpy array are different
149
+
150
+ numpy array values are different \\(50\\.0 %\\)
151
+ \\[left\\]: \\[2011-01-01 00:00:00, 2011-01-01 00:00:00\\]
152
+ \\[right\\]: \\[2011-01-01 00:00:00, 2011-01-02 00:00:00\\]"""
153
+
154
+ with pytest.raises(AssertionError, match=msg):
155
+ tm.assert_numpy_array_equal(a, b)
156
+
157
+
158
+ @pytest.mark.parametrize("other_type", ["same", "copy"])
159
+ @pytest.mark.parametrize("check_same", ["same", "copy"])
160
+ def test_numpy_array_equal_copy_flag(other_type, check_same):
161
+ a = np.array([1, 2, 3])
162
+ msg = None
163
+
164
+ if other_type == "same":
165
+ other = a.view()
166
+ else:
167
+ other = a.copy()
168
+
169
+ if check_same != other_type:
170
+ msg = (
171
+ r"array\(\[1, 2, 3\]\) is not array\(\[1, 2, 3\]\)"
172
+ if check_same == "same"
173
+ else r"array\(\[1, 2, 3\]\) is array\(\[1, 2, 3\]\)"
174
+ )
175
+
176
+ if msg is not None:
177
+ with pytest.raises(AssertionError, match=msg):
178
+ tm.assert_numpy_array_equal(a, other, check_same=check_same)
179
+ else:
180
+ tm.assert_numpy_array_equal(a, other, check_same=check_same)
181
+
182
+
183
+ def test_numpy_array_equal_contains_na():
184
+ # https://github.com/pandas-dev/pandas/issues/31881
185
+ a = np.array([True, False])
186
+ b = np.array([True, pd.NA], dtype=object)
187
+
188
+ msg = """numpy array are different
189
+
190
+ numpy array values are different \\(50.0 %\\)
191
+ \\[left\\]: \\[True, False\\]
192
+ \\[right\\]: \\[True, <NA>\\]"""
193
+
194
+ with pytest.raises(AssertionError, match=msg):
195
+ tm.assert_numpy_array_equal(a, b)
196
+
197
+
198
+ def test_numpy_array_equal_identical_na(nulls_fixture):
199
+ a = np.array([nulls_fixture], dtype=object)
200
+
201
+ tm.assert_numpy_array_equal(a, a)
202
+
203
+ # matching but not the identical object
204
+ if hasattr(nulls_fixture, "copy"):
205
+ other = nulls_fixture.copy()
206
+ else:
207
+ other = copy.copy(nulls_fixture)
208
+ b = np.array([other], dtype=object)
209
+ tm.assert_numpy_array_equal(a, b)
210
+
211
+
212
+ def test_numpy_array_equal_different_na():
213
+ a = np.array([np.nan], dtype=object)
214
+ b = np.array([pd.NA], dtype=object)
215
+
216
+ msg = """numpy array are different
217
+
218
+ numpy array values are different \\(100.0 %\\)
219
+ \\[left\\]: \\[nan\\]
220
+ \\[right\\]: \\[<NA>\\]"""
221
+
222
+ with pytest.raises(AssertionError, match=msg):
223
+ tm.assert_numpy_array_equal(a, b)
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_produces_warning.py ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """"
2
+ Test module for testing ``pandas._testing.assert_produces_warning``.
3
+ """
4
+ import warnings
5
+
6
+ import pytest
7
+
8
+ from pandas.errors import (
9
+ DtypeWarning,
10
+ PerformanceWarning,
11
+ )
12
+
13
+ import pandas._testing as tm
14
+
15
+
16
+ @pytest.fixture(
17
+ params=[
18
+ RuntimeWarning,
19
+ ResourceWarning,
20
+ UserWarning,
21
+ FutureWarning,
22
+ DeprecationWarning,
23
+ PerformanceWarning,
24
+ DtypeWarning,
25
+ ],
26
+ )
27
+ def category(request):
28
+ """
29
+ Return unique warning.
30
+
31
+ Useful for testing behavior of tm.assert_produces_warning with various categories.
32
+ """
33
+ return request.param
34
+
35
+
36
+ @pytest.fixture(
37
+ params=[
38
+ (RuntimeWarning, UserWarning),
39
+ (UserWarning, FutureWarning),
40
+ (FutureWarning, RuntimeWarning),
41
+ (DeprecationWarning, PerformanceWarning),
42
+ (PerformanceWarning, FutureWarning),
43
+ (DtypeWarning, DeprecationWarning),
44
+ (ResourceWarning, DeprecationWarning),
45
+ (FutureWarning, DeprecationWarning),
46
+ ],
47
+ ids=lambda x: type(x).__name__,
48
+ )
49
+ def pair_different_warnings(request):
50
+ """
51
+ Return pair or different warnings.
52
+
53
+ Useful for testing how several different warnings are handled
54
+ in tm.assert_produces_warning.
55
+ """
56
+ return request.param
57
+
58
+
59
+ def f():
60
+ warnings.warn("f1", FutureWarning)
61
+ warnings.warn("f2", RuntimeWarning)
62
+
63
+
64
+ @pytest.mark.filterwarnings("ignore:f1:FutureWarning")
65
+ def test_assert_produces_warning_honors_filter():
66
+ # Raise by default.
67
+ msg = r"Caused unexpected warning\(s\)"
68
+ with pytest.raises(AssertionError, match=msg):
69
+ with tm.assert_produces_warning(RuntimeWarning):
70
+ f()
71
+
72
+ with tm.assert_produces_warning(RuntimeWarning, raise_on_extra_warnings=False):
73
+ f()
74
+
75
+
76
+ @pytest.mark.parametrize(
77
+ "message, match",
78
+ [
79
+ ("", None),
80
+ ("", ""),
81
+ ("Warning message", r".*"),
82
+ ("Warning message", "War"),
83
+ ("Warning message", r"[Ww]arning"),
84
+ ("Warning message", "age"),
85
+ ("Warning message", r"age$"),
86
+ ("Message 12-234 with numbers", r"\d{2}-\d{3}"),
87
+ ("Message 12-234 with numbers", r"^Mes.*\d{2}-\d{3}"),
88
+ ("Message 12-234 with numbers", r"\d{2}-\d{3}\s\S+"),
89
+ ("Message, which we do not match", None),
90
+ ],
91
+ )
92
+ def test_catch_warning_category_and_match(category, message, match):
93
+ with tm.assert_produces_warning(category, match=match):
94
+ warnings.warn(message, category)
95
+
96
+
97
+ def test_fail_to_match_runtime_warning():
98
+ category = RuntimeWarning
99
+ match = "Did not see this warning"
100
+ unmatched = (
101
+ r"Did not see warning 'RuntimeWarning' matching 'Did not see this warning'. "
102
+ r"The emitted warning messages are "
103
+ r"\[RuntimeWarning\('This is not a match.'\), "
104
+ r"RuntimeWarning\('Another unmatched warning.'\)\]"
105
+ )
106
+ with pytest.raises(AssertionError, match=unmatched):
107
+ with tm.assert_produces_warning(category, match=match):
108
+ warnings.warn("This is not a match.", category)
109
+ warnings.warn("Another unmatched warning.", category)
110
+
111
+
112
+ def test_fail_to_match_future_warning():
113
+ category = FutureWarning
114
+ match = "Warning"
115
+ unmatched = (
116
+ r"Did not see warning 'FutureWarning' matching 'Warning'. "
117
+ r"The emitted warning messages are "
118
+ r"\[FutureWarning\('This is not a match.'\), "
119
+ r"FutureWarning\('Another unmatched warning.'\)\]"
120
+ )
121
+ with pytest.raises(AssertionError, match=unmatched):
122
+ with tm.assert_produces_warning(category, match=match):
123
+ warnings.warn("This is not a match.", category)
124
+ warnings.warn("Another unmatched warning.", category)
125
+
126
+
127
+ def test_fail_to_match_resource_warning():
128
+ category = ResourceWarning
129
+ match = r"\d+"
130
+ unmatched = (
131
+ r"Did not see warning 'ResourceWarning' matching '\\d\+'. "
132
+ r"The emitted warning messages are "
133
+ r"\[ResourceWarning\('This is not a match.'\), "
134
+ r"ResourceWarning\('Another unmatched warning.'\)\]"
135
+ )
136
+ with pytest.raises(AssertionError, match=unmatched):
137
+ with tm.assert_produces_warning(category, match=match):
138
+ warnings.warn("This is not a match.", category)
139
+ warnings.warn("Another unmatched warning.", category)
140
+
141
+
142
+ def test_fail_to_catch_actual_warning(pair_different_warnings):
143
+ expected_category, actual_category = pair_different_warnings
144
+ match = "Did not see expected warning of class"
145
+ with pytest.raises(AssertionError, match=match):
146
+ with tm.assert_produces_warning(expected_category):
147
+ warnings.warn("warning message", actual_category)
148
+
149
+
150
+ def test_ignore_extra_warning(pair_different_warnings):
151
+ expected_category, extra_category = pair_different_warnings
152
+ with tm.assert_produces_warning(expected_category, raise_on_extra_warnings=False):
153
+ warnings.warn("Expected warning", expected_category)
154
+ warnings.warn("Unexpected warning OK", extra_category)
155
+
156
+
157
+ def test_raise_on_extra_warning(pair_different_warnings):
158
+ expected_category, extra_category = pair_different_warnings
159
+ match = r"Caused unexpected warning\(s\)"
160
+ with pytest.raises(AssertionError, match=match):
161
+ with tm.assert_produces_warning(expected_category):
162
+ warnings.warn("Expected warning", expected_category)
163
+ warnings.warn("Unexpected warning NOT OK", extra_category)
164
+
165
+
166
+ def test_same_category_different_messages_first_match():
167
+ category = UserWarning
168
+ with tm.assert_produces_warning(category, match=r"^Match this"):
169
+ warnings.warn("Match this", category)
170
+ warnings.warn("Do not match that", category)
171
+ warnings.warn("Do not match that either", category)
172
+
173
+
174
+ def test_same_category_different_messages_last_match():
175
+ category = DeprecationWarning
176
+ with tm.assert_produces_warning(category, match=r"^Match this"):
177
+ warnings.warn("Do not match that", category)
178
+ warnings.warn("Do not match that either", category)
179
+ warnings.warn("Match this", category)
180
+
181
+
182
+ def test_match_multiple_warnings():
183
+ # https://github.com/pandas-dev/pandas/issues/47829
184
+ category = (FutureWarning, UserWarning)
185
+ with tm.assert_produces_warning(category, match=r"^Match this"):
186
+ warnings.warn("Match this", FutureWarning)
187
+ warnings.warn("Match this too", UserWarning)
188
+
189
+
190
+ def test_right_category_wrong_match_raises(pair_different_warnings):
191
+ target_category, other_category = pair_different_warnings
192
+ with pytest.raises(AssertionError, match="Did not see warning.*matching"):
193
+ with tm.assert_produces_warning(target_category, match=r"^Match this"):
194
+ warnings.warn("Do not match it", target_category)
195
+ warnings.warn("Match this", other_category)
196
+
197
+
198
+ @pytest.mark.parametrize("false_or_none", [False, None])
199
+ class TestFalseOrNoneExpectedWarning:
200
+ def test_raise_on_warning(self, false_or_none):
201
+ msg = r"Caused unexpected warning\(s\)"
202
+ with pytest.raises(AssertionError, match=msg):
203
+ with tm.assert_produces_warning(false_or_none):
204
+ f()
205
+
206
+ def test_no_raise_without_warning(self, false_or_none):
207
+ with tm.assert_produces_warning(false_or_none):
208
+ pass
209
+
210
+ def test_no_raise_with_false_raise_on_extra(self, false_or_none):
211
+ with tm.assert_produces_warning(false_or_none, raise_on_extra_warnings=False):
212
+ f()
213
+
214
+
215
+ def test_raises_during_exception():
216
+ msg = "Did not see expected warning of class 'UserWarning'"
217
+ with pytest.raises(AssertionError, match=msg):
218
+ with tm.assert_produces_warning(UserWarning):
219
+ raise ValueError
220
+
221
+ with pytest.raises(AssertionError, match=msg):
222
+ with tm.assert_produces_warning(UserWarning):
223
+ warnings.warn("FutureWarning", FutureWarning)
224
+ raise IndexError
225
+
226
+ msg = "Caused unexpected warning"
227
+ with pytest.raises(AssertionError, match=msg):
228
+ with tm.assert_produces_warning(None):
229
+ warnings.warn("FutureWarning", FutureWarning)
230
+ raise SystemError
231
+
232
+
233
+ def test_passes_during_exception():
234
+ with pytest.raises(SyntaxError, match="Error"):
235
+ with tm.assert_produces_warning(None):
236
+ raise SyntaxError("Error")
237
+
238
+ with pytest.raises(ValueError, match="Error"):
239
+ with tm.assert_produces_warning(FutureWarning, match="FutureWarning"):
240
+ warnings.warn("FutureWarning", FutureWarning)
241
+ raise ValueError("Error")
venv/lib/python3.10/site-packages/pandas/tests/util/test_assert_series_equal.py ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Categorical,
7
+ DataFrame,
8
+ Series,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ def _assert_series_equal_both(a, b, **kwargs):
14
+ """
15
+ Check that two Series equal.
16
+
17
+ This check is performed commutatively.
18
+
19
+ Parameters
20
+ ----------
21
+ a : Series
22
+ The first Series to compare.
23
+ b : Series
24
+ The second Series to compare.
25
+ kwargs : dict
26
+ The arguments passed to `tm.assert_series_equal`.
27
+ """
28
+ tm.assert_series_equal(a, b, **kwargs)
29
+ tm.assert_series_equal(b, a, **kwargs)
30
+
31
+
32
+ def _assert_not_series_equal(a, b, **kwargs):
33
+ """
34
+ Check that two Series are not equal.
35
+
36
+ Parameters
37
+ ----------
38
+ a : Series
39
+ The first Series to compare.
40
+ b : Series
41
+ The second Series to compare.
42
+ kwargs : dict
43
+ The arguments passed to `tm.assert_series_equal`.
44
+ """
45
+ try:
46
+ tm.assert_series_equal(a, b, **kwargs)
47
+ msg = "The two Series were equal when they shouldn't have been"
48
+
49
+ pytest.fail(msg=msg)
50
+ except AssertionError:
51
+ pass
52
+
53
+
54
+ def _assert_not_series_equal_both(a, b, **kwargs):
55
+ """
56
+ Check that two Series are not equal.
57
+
58
+ This check is performed commutatively.
59
+
60
+ Parameters
61
+ ----------
62
+ a : Series
63
+ The first Series to compare.
64
+ b : Series
65
+ The second Series to compare.
66
+ kwargs : dict
67
+ The arguments passed to `tm.assert_series_equal`.
68
+ """
69
+ _assert_not_series_equal(a, b, **kwargs)
70
+ _assert_not_series_equal(b, a, **kwargs)
71
+
72
+
73
+ @pytest.mark.parametrize("data", [range(3), list("abc"), list("áàä")])
74
+ def test_series_equal(data):
75
+ _assert_series_equal_both(Series(data), Series(data))
76
+
77
+
78
+ @pytest.mark.parametrize(
79
+ "data1,data2",
80
+ [
81
+ (range(3), range(1, 4)),
82
+ (list("abc"), list("xyz")),
83
+ (list("áàä"), list("éèë")),
84
+ (list("áàä"), list(b"aaa")),
85
+ (range(3), range(4)),
86
+ ],
87
+ )
88
+ def test_series_not_equal_value_mismatch(data1, data2):
89
+ _assert_not_series_equal_both(Series(data1), Series(data2))
90
+
91
+
92
+ @pytest.mark.parametrize(
93
+ "kwargs",
94
+ [
95
+ {"dtype": "float64"}, # dtype mismatch
96
+ {"index": [1, 2, 4]}, # index mismatch
97
+ {"name": "foo"}, # name mismatch
98
+ ],
99
+ )
100
+ def test_series_not_equal_metadata_mismatch(kwargs):
101
+ data = range(3)
102
+ s1 = Series(data)
103
+
104
+ s2 = Series(data, **kwargs)
105
+ _assert_not_series_equal_both(s1, s2)
106
+
107
+
108
+ @pytest.mark.parametrize("data1,data2", [(0.12345, 0.12346), (0.1235, 0.1236)])
109
+ @pytest.mark.parametrize("dtype", ["float32", "float64", "Float32"])
110
+ @pytest.mark.parametrize("decimals", [0, 1, 2, 3, 5, 10])
111
+ def test_less_precise(data1, data2, dtype, decimals):
112
+ rtol = 10**-decimals
113
+ s1 = Series([data1], dtype=dtype)
114
+ s2 = Series([data2], dtype=dtype)
115
+
116
+ if decimals in (5, 10) or (decimals >= 3 and abs(data1 - data2) >= 0.0005):
117
+ msg = "Series values are different"
118
+ with pytest.raises(AssertionError, match=msg):
119
+ tm.assert_series_equal(s1, s2, rtol=rtol)
120
+ else:
121
+ _assert_series_equal_both(s1, s2, rtol=rtol)
122
+
123
+
124
+ @pytest.mark.parametrize(
125
+ "s1,s2,msg",
126
+ [
127
+ # Index
128
+ (
129
+ Series(["l1", "l2"], index=[1, 2]),
130
+ Series(["l1", "l2"], index=[1.0, 2.0]),
131
+ "Series\\.index are different",
132
+ ),
133
+ # MultiIndex
134
+ (
135
+ DataFrame.from_records(
136
+ {"a": [1, 2], "b": [2.1, 1.5], "c": ["l1", "l2"]}, index=["a", "b"]
137
+ ).c,
138
+ DataFrame.from_records(
139
+ {"a": [1.0, 2.0], "b": [2.1, 1.5], "c": ["l1", "l2"]}, index=["a", "b"]
140
+ ).c,
141
+ "MultiIndex level \\[0\\] are different",
142
+ ),
143
+ ],
144
+ )
145
+ def test_series_equal_index_dtype(s1, s2, msg, check_index_type):
146
+ kwargs = {"check_index_type": check_index_type}
147
+
148
+ if check_index_type:
149
+ with pytest.raises(AssertionError, match=msg):
150
+ tm.assert_series_equal(s1, s2, **kwargs)
151
+ else:
152
+ tm.assert_series_equal(s1, s2, **kwargs)
153
+
154
+
155
+ @pytest.mark.parametrize("check_like", [True, False])
156
+ def test_series_equal_order_mismatch(check_like):
157
+ s1 = Series([1, 2, 3], index=["a", "b", "c"])
158
+ s2 = Series([3, 2, 1], index=["c", "b", "a"])
159
+
160
+ if not check_like: # Do not ignore index ordering.
161
+ with pytest.raises(AssertionError, match="Series.index are different"):
162
+ tm.assert_series_equal(s1, s2, check_like=check_like)
163
+ else:
164
+ _assert_series_equal_both(s1, s2, check_like=check_like)
165
+
166
+
167
+ @pytest.mark.parametrize("check_index", [True, False])
168
+ def test_series_equal_index_mismatch(check_index):
169
+ s1 = Series([1, 2, 3], index=["a", "b", "c"])
170
+ s2 = Series([1, 2, 3], index=["c", "b", "a"])
171
+
172
+ if check_index: # Do not ignore index.
173
+ with pytest.raises(AssertionError, match="Series.index are different"):
174
+ tm.assert_series_equal(s1, s2, check_index=check_index)
175
+ else:
176
+ _assert_series_equal_both(s1, s2, check_index=check_index)
177
+
178
+
179
+ def test_series_invalid_param_combination():
180
+ left = Series(dtype=object)
181
+ right = Series(dtype=object)
182
+ with pytest.raises(
183
+ ValueError, match="check_like must be False if check_index is False"
184
+ ):
185
+ tm.assert_series_equal(left, right, check_index=False, check_like=True)
186
+
187
+
188
+ def test_series_equal_length_mismatch(rtol):
189
+ msg = """Series are different
190
+
191
+ Series length are different
192
+ \\[left\\]: 3, RangeIndex\\(start=0, stop=3, step=1\\)
193
+ \\[right\\]: 4, RangeIndex\\(start=0, stop=4, step=1\\)"""
194
+
195
+ s1 = Series([1, 2, 3])
196
+ s2 = Series([1, 2, 3, 4])
197
+
198
+ with pytest.raises(AssertionError, match=msg):
199
+ tm.assert_series_equal(s1, s2, rtol=rtol)
200
+
201
+
202
+ def test_series_equal_numeric_values_mismatch(rtol):
203
+ msg = """Series are different
204
+
205
+ Series values are different \\(33\\.33333 %\\)
206
+ \\[index\\]: \\[0, 1, 2\\]
207
+ \\[left\\]: \\[1, 2, 3\\]
208
+ \\[right\\]: \\[1, 2, 4\\]"""
209
+
210
+ s1 = Series([1, 2, 3])
211
+ s2 = Series([1, 2, 4])
212
+
213
+ with pytest.raises(AssertionError, match=msg):
214
+ tm.assert_series_equal(s1, s2, rtol=rtol)
215
+
216
+
217
+ def test_series_equal_categorical_values_mismatch(rtol, using_infer_string):
218
+ if using_infer_string:
219
+ msg = """Series are different
220
+
221
+ Series values are different \\(66\\.66667 %\\)
222
+ \\[index\\]: \\[0, 1, 2\\]
223
+ \\[left\\]: \\['a', 'b', 'c'\\]
224
+ Categories \\(3, string\\): \\[a, b, c\\]
225
+ \\[right\\]: \\['a', 'c', 'b'\\]
226
+ Categories \\(3, string\\): \\[a, b, c\\]"""
227
+ else:
228
+ msg = """Series are different
229
+
230
+ Series values are different \\(66\\.66667 %\\)
231
+ \\[index\\]: \\[0, 1, 2\\]
232
+ \\[left\\]: \\['a', 'b', 'c'\\]
233
+ Categories \\(3, object\\): \\['a', 'b', 'c'\\]
234
+ \\[right\\]: \\['a', 'c', 'b'\\]
235
+ Categories \\(3, object\\): \\['a', 'b', 'c'\\]"""
236
+
237
+ s1 = Series(Categorical(["a", "b", "c"]))
238
+ s2 = Series(Categorical(["a", "c", "b"]))
239
+
240
+ with pytest.raises(AssertionError, match=msg):
241
+ tm.assert_series_equal(s1, s2, rtol=rtol)
242
+
243
+
244
+ def test_series_equal_datetime_values_mismatch(rtol):
245
+ msg = """Series are different
246
+
247
+ Series values are different \\(100.0 %\\)
248
+ \\[index\\]: \\[0, 1, 2\\]
249
+ \\[left\\]: \\[1514764800000000000, 1514851200000000000, 1514937600000000000\\]
250
+ \\[right\\]: \\[1549065600000000000, 1549152000000000000, 1549238400000000000\\]"""
251
+
252
+ s1 = Series(pd.date_range("2018-01-01", periods=3, freq="D"))
253
+ s2 = Series(pd.date_range("2019-02-02", periods=3, freq="D"))
254
+
255
+ with pytest.raises(AssertionError, match=msg):
256
+ tm.assert_series_equal(s1, s2, rtol=rtol)
257
+
258
+
259
+ def test_series_equal_categorical_mismatch(check_categorical, using_infer_string):
260
+ if using_infer_string:
261
+ dtype = "string"
262
+ else:
263
+ dtype = "object"
264
+ msg = f"""Attributes of Series are different
265
+
266
+ Attribute "dtype" are different
267
+ \\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False, \
268
+ categories_dtype={dtype}\\)
269
+ \\[right\\]: CategoricalDtype\\(categories=\\['a', 'b', 'c'\\], \
270
+ ordered=False, categories_dtype={dtype}\\)"""
271
+
272
+ s1 = Series(Categorical(["a", "b"]))
273
+ s2 = Series(Categorical(["a", "b"], categories=list("abc")))
274
+
275
+ if check_categorical:
276
+ with pytest.raises(AssertionError, match=msg):
277
+ tm.assert_series_equal(s1, s2, check_categorical=check_categorical)
278
+ else:
279
+ _assert_series_equal_both(s1, s2, check_categorical=check_categorical)
280
+
281
+
282
+ def test_assert_series_equal_extension_dtype_mismatch():
283
+ # https://github.com/pandas-dev/pandas/issues/32747
284
+ left = Series(pd.array([1, 2, 3], dtype="Int64"))
285
+ right = left.astype(int)
286
+
287
+ msg = """Attributes of Series are different
288
+
289
+ Attribute "dtype" are different
290
+ \\[left\\]: Int64
291
+ \\[right\\]: int[32|64]"""
292
+
293
+ tm.assert_series_equal(left, right, check_dtype=False)
294
+
295
+ with pytest.raises(AssertionError, match=msg):
296
+ tm.assert_series_equal(left, right, check_dtype=True)
297
+
298
+
299
+ def test_assert_series_equal_interval_dtype_mismatch():
300
+ # https://github.com/pandas-dev/pandas/issues/32747
301
+ left = Series([pd.Interval(0, 1)], dtype="interval")
302
+ right = left.astype(object)
303
+
304
+ msg = """Attributes of Series are different
305
+
306
+ Attribute "dtype" are different
307
+ \\[left\\]: interval\\[int64, right\\]
308
+ \\[right\\]: object"""
309
+
310
+ tm.assert_series_equal(left, right, check_dtype=False)
311
+
312
+ with pytest.raises(AssertionError, match=msg):
313
+ tm.assert_series_equal(left, right, check_dtype=True)
314
+
315
+
316
+ def test_series_equal_series_type():
317
+ class MySeries(Series):
318
+ pass
319
+
320
+ s1 = Series([1, 2])
321
+ s2 = Series([1, 2])
322
+ s3 = MySeries([1, 2])
323
+
324
+ tm.assert_series_equal(s1, s2, check_series_type=False)
325
+ tm.assert_series_equal(s1, s2, check_series_type=True)
326
+
327
+ tm.assert_series_equal(s1, s3, check_series_type=False)
328
+ tm.assert_series_equal(s3, s1, check_series_type=False)
329
+
330
+ with pytest.raises(AssertionError, match="Series classes are different"):
331
+ tm.assert_series_equal(s1, s3, check_series_type=True)
332
+
333
+ with pytest.raises(AssertionError, match="Series classes are different"):
334
+ tm.assert_series_equal(s3, s1, check_series_type=True)
335
+
336
+
337
+ def test_series_equal_exact_for_nonnumeric():
338
+ # https://github.com/pandas-dev/pandas/issues/35446
339
+ s1 = Series(["a", "b"])
340
+ s2 = Series(["a", "b"])
341
+ s3 = Series(["b", "a"])
342
+
343
+ tm.assert_series_equal(s1, s2, check_exact=True)
344
+ tm.assert_series_equal(s2, s1, check_exact=True)
345
+
346
+ msg = """Series are different
347
+
348
+ Series values are different \\(100\\.0 %\\)
349
+ \\[index\\]: \\[0, 1\\]
350
+ \\[left\\]: \\[a, b\\]
351
+ \\[right\\]: \\[b, a\\]"""
352
+ with pytest.raises(AssertionError, match=msg):
353
+ tm.assert_series_equal(s1, s3, check_exact=True)
354
+
355
+ msg = """Series are different
356
+
357
+ Series values are different \\(100\\.0 %\\)
358
+ \\[index\\]: \\[0, 1\\]
359
+ \\[left\\]: \\[b, a\\]
360
+ \\[right\\]: \\[a, b\\]"""
361
+ with pytest.raises(AssertionError, match=msg):
362
+ tm.assert_series_equal(s3, s1, check_exact=True)
363
+
364
+
365
+ def test_assert_series_equal_ignore_extension_dtype_mismatch():
366
+ # https://github.com/pandas-dev/pandas/issues/35715
367
+ left = Series([1, 2, 3], dtype="Int64")
368
+ right = Series([1, 2, 3], dtype="Int32")
369
+ tm.assert_series_equal(left, right, check_dtype=False)
370
+
371
+
372
+ def test_assert_series_equal_ignore_extension_dtype_mismatch_cross_class():
373
+ # https://github.com/pandas-dev/pandas/issues/35715
374
+ left = Series([1, 2, 3], dtype="Int64")
375
+ right = Series([1, 2, 3], dtype="int64")
376
+ tm.assert_series_equal(left, right, check_dtype=False)
377
+
378
+
379
+ def test_allows_duplicate_labels():
380
+ left = Series([1])
381
+ right = Series([1]).set_flags(allows_duplicate_labels=False)
382
+ tm.assert_series_equal(left, left)
383
+ tm.assert_series_equal(right, right)
384
+ tm.assert_series_equal(left, right, check_flags=False)
385
+ tm.assert_series_equal(right, left, check_flags=False)
386
+
387
+ with pytest.raises(AssertionError, match="<Flags"):
388
+ tm.assert_series_equal(left, right)
389
+
390
+ with pytest.raises(AssertionError, match="<Flags"):
391
+ tm.assert_series_equal(left, right)
392
+
393
+
394
+ def test_assert_series_equal_identical_na(nulls_fixture):
395
+ ser = Series([nulls_fixture])
396
+
397
+ tm.assert_series_equal(ser, ser.copy())
398
+
399
+ # while we're here do Index too
400
+ idx = pd.Index(ser)
401
+ tm.assert_index_equal(idx, idx.copy(deep=True))
402
+
403
+
404
+ def test_identical_nested_series_is_equal():
405
+ # GH#22400
406
+ x = Series(
407
+ [
408
+ 0,
409
+ 0.0131142231938,
410
+ 1.77774652865e-05,
411
+ np.array([0.4722720840328748, 0.4216929783681722]),
412
+ ]
413
+ )
414
+ y = Series(
415
+ [
416
+ 0,
417
+ 0.0131142231938,
418
+ 1.77774652865e-05,
419
+ np.array([0.4722720840328748, 0.4216929783681722]),
420
+ ]
421
+ )
422
+ # These two arrays should be equal, nesting could cause issue
423
+
424
+ tm.assert_series_equal(x, x)
425
+ tm.assert_series_equal(x, x, check_exact=True)
426
+ tm.assert_series_equal(x, y)
427
+ tm.assert_series_equal(x, y, check_exact=True)
428
+
429
+
430
+ @pytest.mark.parametrize("dtype", ["datetime64", "timedelta64"])
431
+ def test_check_dtype_false_different_reso(dtype):
432
+ # GH 52449
433
+ ser_s = Series([1000213, 2131232, 21312331]).astype(f"{dtype}[s]")
434
+ ser_ms = ser_s.astype(f"{dtype}[ms]")
435
+ with pytest.raises(AssertionError, match="Attributes of Series are different"):
436
+ tm.assert_series_equal(ser_s, ser_ms)
437
+ tm.assert_series_equal(ser_ms, ser_s, check_dtype=False)
438
+
439
+ ser_ms -= Series([1, 1, 1]).astype(f"{dtype}[ms]")
440
+
441
+ with pytest.raises(AssertionError, match="Series are different"):
442
+ tm.assert_series_equal(ser_s, ser_ms)
443
+
444
+ with pytest.raises(AssertionError, match="Series are different"):
445
+ tm.assert_series_equal(ser_s, ser_ms, check_dtype=False)
446
+
447
+
448
+ @pytest.mark.parametrize("dtype", ["Int64", "int64"])
449
+ def test_large_unequal_ints(dtype):
450
+ # https://github.com/pandas-dev/pandas/issues/55882
451
+ left = Series([1577840521123000], dtype=dtype)
452
+ right = Series([1577840521123543], dtype=dtype)
453
+ with pytest.raises(AssertionError, match="Series are different"):
454
+ tm.assert_series_equal(left, right)
455
+
456
+
457
+ @pytest.mark.parametrize("dtype", [None, object])
458
+ @pytest.mark.parametrize("check_exact", [True, False])
459
+ @pytest.mark.parametrize("val", [3, 3.5])
460
+ def test_ea_and_numpy_no_dtype_check(val, check_exact, dtype):
461
+ # GH#56651
462
+ left = Series([1, 2, val], dtype=dtype)
463
+ right = Series(pd.array([1, 2, val]))
464
+ tm.assert_series_equal(left, right, check_dtype=False, check_exact=check_exact)
465
+
466
+
467
+ def test_assert_series_equal_int_tol():
468
+ # GH#56646
469
+ left = Series([81, 18, 121, 38, 74, 72, 81, 81, 146, 81, 81, 170, 74, 74])
470
+ right = Series([72, 9, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72])
471
+ tm.assert_series_equal(left, right, rtol=1.5)
472
+
473
+ tm.assert_frame_equal(left.to_frame(), right.to_frame(), rtol=1.5)
474
+ tm.assert_extension_array_equal(
475
+ left.astype("Int64").values, right.astype("Int64").values, rtol=1.5
476
+ )
477
+
478
+
479
+ def test_assert_series_equal_index_exact_default():
480
+ # GH#57067
481
+ ser1 = Series(np.zeros(6, dtype=int), [0, 0.2, 0.4, 0.6, 0.8, 1])
482
+ ser2 = Series(np.zeros(6, dtype=int), np.linspace(0, 1, 6))
483
+ tm.assert_series_equal(ser1, ser2)
484
+ tm.assert_frame_equal(ser1.to_frame(), ser2.to_frame())
venv/lib/python3.10/site-packages/pandas/tests/util/test_deprecate.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from textwrap import dedent
2
+
3
+ import pytest
4
+
5
+ from pandas.util._decorators import deprecate
6
+
7
+ import pandas._testing as tm
8
+
9
+
10
+ def new_func():
11
+ """
12
+ This is the summary. The deprecate directive goes next.
13
+
14
+ This is the extended summary. The deprecate directive goes before this.
15
+ """
16
+ return "new_func called"
17
+
18
+
19
+ def new_func_no_docstring():
20
+ return "new_func_no_docstring called"
21
+
22
+
23
+ def new_func_wrong_docstring():
24
+ """Summary should be in the next line."""
25
+ return "new_func_wrong_docstring called"
26
+
27
+
28
+ def new_func_with_deprecation():
29
+ """
30
+ This is the summary. The deprecate directive goes next.
31
+
32
+ .. deprecated:: 1.0
33
+ Use new_func instead.
34
+
35
+ This is the extended summary. The deprecate directive goes before this.
36
+ """
37
+
38
+
39
+ def test_deprecate_ok():
40
+ depr_func = deprecate("depr_func", new_func, "1.0", msg="Use new_func instead.")
41
+
42
+ with tm.assert_produces_warning(FutureWarning):
43
+ result = depr_func()
44
+
45
+ assert result == "new_func called"
46
+ assert depr_func.__doc__ == dedent(new_func_with_deprecation.__doc__)
47
+
48
+
49
+ def test_deprecate_no_docstring():
50
+ depr_func = deprecate(
51
+ "depr_func", new_func_no_docstring, "1.0", msg="Use new_func instead."
52
+ )
53
+ with tm.assert_produces_warning(FutureWarning):
54
+ result = depr_func()
55
+ assert result == "new_func_no_docstring called"
56
+
57
+
58
+ def test_deprecate_wrong_docstring():
59
+ msg = "deprecate needs a correctly formatted docstring"
60
+ with pytest.raises(AssertionError, match=msg):
61
+ deprecate(
62
+ "depr_func", new_func_wrong_docstring, "1.0", msg="Use new_func instead."
63
+ )
venv/lib/python3.10/site-packages/pandas/tests/util/test_deprecate_kwarg.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas.util._decorators import deprecate_kwarg
4
+
5
+ import pandas._testing as tm
6
+
7
+
8
+ @deprecate_kwarg("old", "new")
9
+ def _f1(new=False):
10
+ return new
11
+
12
+
13
+ _f2_mappings = {"yes": True, "no": False}
14
+
15
+
16
+ @deprecate_kwarg("old", "new", _f2_mappings)
17
+ def _f2(new=False):
18
+ return new
19
+
20
+
21
+ def _f3_mapping(x):
22
+ return x + 1
23
+
24
+
25
+ @deprecate_kwarg("old", "new", _f3_mapping)
26
+ def _f3(new=0):
27
+ return new
28
+
29
+
30
+ @pytest.mark.parametrize("key,klass", [("old", FutureWarning), ("new", None)])
31
+ def test_deprecate_kwarg(key, klass):
32
+ x = 78
33
+
34
+ with tm.assert_produces_warning(klass):
35
+ assert _f1(**{key: x}) == x
36
+
37
+
38
+ @pytest.mark.parametrize("key", list(_f2_mappings.keys()))
39
+ def test_dict_deprecate_kwarg(key):
40
+ with tm.assert_produces_warning(FutureWarning):
41
+ assert _f2(old=key) == _f2_mappings[key]
42
+
43
+
44
+ @pytest.mark.parametrize("key", ["bogus", 12345, -1.23])
45
+ def test_missing_deprecate_kwarg(key):
46
+ with tm.assert_produces_warning(FutureWarning):
47
+ assert _f2(old=key) == key
48
+
49
+
50
+ @pytest.mark.parametrize("x", [1, -1.4, 0])
51
+ def test_callable_deprecate_kwarg(x):
52
+ with tm.assert_produces_warning(FutureWarning):
53
+ assert _f3(old=x) == _f3_mapping(x)
54
+
55
+
56
+ def test_callable_deprecate_kwarg_fail():
57
+ msg = "((can only|cannot) concatenate)|(must be str)|(Can't convert)"
58
+
59
+ with pytest.raises(TypeError, match=msg):
60
+ _f3(old="hello")
61
+
62
+
63
+ def test_bad_deprecate_kwarg():
64
+ msg = "mapping from old to new argument values must be dict or callable!"
65
+
66
+ with pytest.raises(TypeError, match=msg):
67
+
68
+ @deprecate_kwarg("old", "new", 0)
69
+ def f4(new=None):
70
+ return new
71
+
72
+
73
+ @deprecate_kwarg("old", None)
74
+ def _f4(old=True, unchanged=True):
75
+ return old, unchanged
76
+
77
+
78
+ @pytest.mark.parametrize("key", ["old", "unchanged"])
79
+ def test_deprecate_keyword(key):
80
+ x = 9
81
+
82
+ if key == "old":
83
+ klass = FutureWarning
84
+ expected = (x, True)
85
+ else:
86
+ klass = None
87
+ expected = (True, x)
88
+
89
+ with tm.assert_produces_warning(klass):
90
+ assert _f4(**{key: x}) == expected
venv/lib/python3.10/site-packages/pandas/tests/util/test_deprecate_nonkeyword_arguments.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tests for the `deprecate_nonkeyword_arguments` decorator
3
+ """
4
+
5
+ import inspect
6
+
7
+ from pandas.util._decorators import deprecate_nonkeyword_arguments
8
+
9
+ import pandas._testing as tm
10
+
11
+
12
+ @deprecate_nonkeyword_arguments(
13
+ version="1.1", allowed_args=["a", "b"], name="f_add_inputs"
14
+ )
15
+ def f(a, b=0, c=0, d=0):
16
+ return a + b + c + d
17
+
18
+
19
+ def test_f_signature():
20
+ assert str(inspect.signature(f)) == "(a, b=0, *, c=0, d=0)"
21
+
22
+
23
+ def test_one_argument():
24
+ with tm.assert_produces_warning(None):
25
+ assert f(19) == 19
26
+
27
+
28
+ def test_one_and_one_arguments():
29
+ with tm.assert_produces_warning(None):
30
+ assert f(19, d=6) == 25
31
+
32
+
33
+ def test_two_arguments():
34
+ with tm.assert_produces_warning(None):
35
+ assert f(1, 5) == 6
36
+
37
+
38
+ def test_two_and_two_arguments():
39
+ with tm.assert_produces_warning(None):
40
+ assert f(1, 3, c=3, d=5) == 12
41
+
42
+
43
+ def test_three_arguments():
44
+ with tm.assert_produces_warning(FutureWarning):
45
+ assert f(6, 3, 3) == 12
46
+
47
+
48
+ def test_four_arguments():
49
+ with tm.assert_produces_warning(FutureWarning):
50
+ assert f(1, 2, 3, 4) == 10
51
+
52
+
53
+ def test_three_arguments_with_name_in_warning():
54
+ msg = (
55
+ "Starting with pandas version 1.1 all arguments of f_add_inputs "
56
+ "except for the arguments 'a' and 'b' will be keyword-only."
57
+ )
58
+ with tm.assert_produces_warning(FutureWarning, match=msg):
59
+ assert f(6, 3, 3) == 12
60
+
61
+
62
+ @deprecate_nonkeyword_arguments(version="1.1")
63
+ def g(a, b=0, c=0, d=0):
64
+ with tm.assert_produces_warning(None):
65
+ return a + b + c + d
66
+
67
+
68
+ def test_g_signature():
69
+ assert str(inspect.signature(g)) == "(a, *, b=0, c=0, d=0)"
70
+
71
+
72
+ def test_one_and_three_arguments_default_allowed_args():
73
+ with tm.assert_produces_warning(None):
74
+ assert g(1, b=3, c=3, d=5) == 12
75
+
76
+
77
+ def test_three_arguments_default_allowed_args():
78
+ with tm.assert_produces_warning(FutureWarning):
79
+ assert g(6, 3, 3) == 12
80
+
81
+
82
+ def test_three_positional_argument_with_warning_message_analysis():
83
+ msg = (
84
+ "Starting with pandas version 1.1 all arguments of g "
85
+ "except for the argument 'a' will be keyword-only."
86
+ )
87
+ with tm.assert_produces_warning(FutureWarning, match=msg):
88
+ assert g(6, 3, 3) == 12
89
+
90
+
91
+ @deprecate_nonkeyword_arguments(version="1.1")
92
+ def h(a=0, b=0, c=0, d=0):
93
+ return a + b + c + d
94
+
95
+
96
+ def test_h_signature():
97
+ assert str(inspect.signature(h)) == "(*, a=0, b=0, c=0, d=0)"
98
+
99
+
100
+ def test_all_keyword_arguments():
101
+ with tm.assert_produces_warning(None):
102
+ assert h(a=1, b=2) == 3
103
+
104
+
105
+ def test_one_positional_argument():
106
+ with tm.assert_produces_warning(FutureWarning):
107
+ assert h(23) == 23
108
+
109
+
110
+ def test_one_positional_argument_with_warning_message_analysis():
111
+ msg = "Starting with pandas version 1.1 all arguments of h will be keyword-only."
112
+ with tm.assert_produces_warning(FutureWarning, match=msg):
113
+ assert h(19) == 19
114
+
115
+
116
+ @deprecate_nonkeyword_arguments(version="1.1")
117
+ def i(a=0, /, b=0, *, c=0, d=0):
118
+ return a + b + c + d
119
+
120
+
121
+ def test_i_signature():
122
+ assert str(inspect.signature(i)) == "(*, a=0, b=0, c=0, d=0)"
123
+
124
+
125
+ class Foo:
126
+ @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "bar"])
127
+ def baz(self, bar=None, foobar=None): # pylint: disable=disallowed-name
128
+ ...
129
+
130
+
131
+ def test_foo_signature():
132
+ assert str(inspect.signature(Foo.baz)) == "(self, bar=None, *, foobar=None)"
133
+
134
+
135
+ def test_class():
136
+ msg = (
137
+ r"In a future version of pandas all arguments of Foo\.baz "
138
+ r"except for the argument \'bar\' will be keyword-only"
139
+ )
140
+ with tm.assert_produces_warning(FutureWarning, match=msg):
141
+ Foo().baz("qux", "quox")
venv/lib/python3.10/site-packages/pandas/tests/util/test_doc.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from textwrap import dedent
2
+
3
+ from pandas.util._decorators import doc
4
+
5
+
6
+ @doc(method="cumsum", operation="sum")
7
+ def cumsum(whatever):
8
+ """
9
+ This is the {method} method.
10
+
11
+ It computes the cumulative {operation}.
12
+ """
13
+
14
+
15
+ @doc(
16
+ cumsum,
17
+ dedent(
18
+ """
19
+ Examples
20
+ --------
21
+
22
+ >>> cumavg([1, 2, 3])
23
+ 2
24
+ """
25
+ ),
26
+ method="cumavg",
27
+ operation="average",
28
+ )
29
+ def cumavg(whatever):
30
+ pass
31
+
32
+
33
+ @doc(cumsum, method="cummax", operation="maximum")
34
+ def cummax(whatever):
35
+ pass
36
+
37
+
38
+ @doc(cummax, method="cummin", operation="minimum")
39
+ def cummin(whatever):
40
+ pass
41
+
42
+
43
+ def test_docstring_formatting():
44
+ docstr = dedent(
45
+ """
46
+ This is the cumsum method.
47
+
48
+ It computes the cumulative sum.
49
+ """
50
+ )
51
+ assert cumsum.__doc__ == docstr
52
+
53
+
54
+ def test_docstring_appending():
55
+ docstr = dedent(
56
+ """
57
+ This is the cumavg method.
58
+
59
+ It computes the cumulative average.
60
+
61
+ Examples
62
+ --------
63
+
64
+ >>> cumavg([1, 2, 3])
65
+ 2
66
+ """
67
+ )
68
+ assert cumavg.__doc__ == docstr
69
+
70
+
71
+ def test_doc_template_from_func():
72
+ docstr = dedent(
73
+ """
74
+ This is the cummax method.
75
+
76
+ It computes the cumulative maximum.
77
+ """
78
+ )
79
+ assert cummax.__doc__ == docstr
80
+
81
+
82
+ def test_inherit_doc_template():
83
+ docstr = dedent(
84
+ """
85
+ This is the cummin method.
86
+
87
+ It computes the cumulative minimum.
88
+ """
89
+ )
90
+ assert cummin.__doc__ == docstr
venv/lib/python3.10/site-packages/pandas/tests/util/test_hashing.py ADDED
@@ -0,0 +1,417 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ DataFrame,
7
+ Index,
8
+ MultiIndex,
9
+ Series,
10
+ period_range,
11
+ timedelta_range,
12
+ )
13
+ import pandas._testing as tm
14
+ from pandas.core.util.hashing import hash_tuples
15
+ from pandas.util import (
16
+ hash_array,
17
+ hash_pandas_object,
18
+ )
19
+
20
+
21
+ @pytest.fixture(
22
+ params=[
23
+ Series([1, 2, 3] * 3, dtype="int32"),
24
+ Series([None, 2.5, 3.5] * 3, dtype="float32"),
25
+ Series(["a", "b", "c"] * 3, dtype="category"),
26
+ Series(["d", "e", "f"] * 3),
27
+ Series([True, False, True] * 3),
28
+ Series(pd.date_range("20130101", periods=9)),
29
+ Series(pd.date_range("20130101", periods=9, tz="US/Eastern")),
30
+ Series(timedelta_range("2000", periods=9)),
31
+ ]
32
+ )
33
+ def series(request):
34
+ return request.param
35
+
36
+
37
+ @pytest.fixture(params=[True, False])
38
+ def index(request):
39
+ return request.param
40
+
41
+
42
+ def test_consistency():
43
+ # Check that our hash doesn't change because of a mistake
44
+ # in the actual code; this is the ground truth.
45
+ result = hash_pandas_object(Index(["foo", "bar", "baz"]))
46
+ expected = Series(
47
+ np.array(
48
+ [3600424527151052760, 1374399572096150070, 477881037637427054],
49
+ dtype="uint64",
50
+ ),
51
+ index=["foo", "bar", "baz"],
52
+ )
53
+ tm.assert_series_equal(result, expected)
54
+
55
+
56
+ def test_hash_array(series):
57
+ arr = series.values
58
+ tm.assert_numpy_array_equal(hash_array(arr), hash_array(arr))
59
+
60
+
61
+ @pytest.mark.parametrize("dtype", ["U", object])
62
+ def test_hash_array_mixed(dtype):
63
+ result1 = hash_array(np.array(["3", "4", "All"]))
64
+ result2 = hash_array(np.array([3, 4, "All"], dtype=dtype))
65
+
66
+ tm.assert_numpy_array_equal(result1, result2)
67
+
68
+
69
+ @pytest.mark.parametrize("val", [5, "foo", pd.Timestamp("20130101")])
70
+ def test_hash_array_errors(val):
71
+ msg = "must pass a ndarray-like"
72
+ with pytest.raises(TypeError, match=msg):
73
+ hash_array(val)
74
+
75
+
76
+ def test_hash_array_index_exception():
77
+ # GH42003 TypeError instead of AttributeError
78
+ obj = pd.DatetimeIndex(["2018-10-28 01:20:00"], tz="Europe/Berlin")
79
+
80
+ msg = "Use hash_pandas_object instead"
81
+ with pytest.raises(TypeError, match=msg):
82
+ hash_array(obj)
83
+
84
+
85
+ def test_hash_tuples():
86
+ tuples = [(1, "one"), (1, "two"), (2, "one")]
87
+ result = hash_tuples(tuples)
88
+
89
+ expected = hash_pandas_object(MultiIndex.from_tuples(tuples)).values
90
+ tm.assert_numpy_array_equal(result, expected)
91
+
92
+ # We only need to support MultiIndex and list-of-tuples
93
+ msg = "|".join(["object is not iterable", "zip argument #1 must support iteration"])
94
+ with pytest.raises(TypeError, match=msg):
95
+ hash_tuples(tuples[0])
96
+
97
+
98
+ @pytest.mark.parametrize("val", [5, "foo", pd.Timestamp("20130101")])
99
+ def test_hash_tuples_err(val):
100
+ msg = "must be convertible to a list-of-tuples"
101
+ with pytest.raises(TypeError, match=msg):
102
+ hash_tuples(val)
103
+
104
+
105
+ def test_multiindex_unique():
106
+ mi = MultiIndex.from_tuples([(118, 472), (236, 118), (51, 204), (102, 51)])
107
+ assert mi.is_unique is True
108
+
109
+ result = hash_pandas_object(mi)
110
+ assert result.is_unique is True
111
+
112
+
113
+ def test_multiindex_objects():
114
+ mi = MultiIndex(
115
+ levels=[["b", "d", "a"], [1, 2, 3]],
116
+ codes=[[0, 1, 0, 2], [2, 0, 0, 1]],
117
+ names=["col1", "col2"],
118
+ )
119
+ recons = mi._sort_levels_monotonic()
120
+
121
+ # These are equal.
122
+ assert mi.equals(recons)
123
+ assert Index(mi.values).equals(Index(recons.values))
124
+
125
+
126
+ @pytest.mark.parametrize(
127
+ "obj",
128
+ [
129
+ Series([1, 2, 3]),
130
+ Series([1.0, 1.5, 3.2]),
131
+ Series([1.0, 1.5, np.nan]),
132
+ Series([1.0, 1.5, 3.2], index=[1.5, 1.1, 3.3]),
133
+ Series(["a", "b", "c"]),
134
+ Series(["a", np.nan, "c"]),
135
+ Series(["a", None, "c"]),
136
+ Series([True, False, True]),
137
+ Series(dtype=object),
138
+ DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3]}),
139
+ DataFrame(),
140
+ DataFrame(np.full((10, 4), np.nan)),
141
+ DataFrame(
142
+ {
143
+ "A": [0.0, 1.0, 2.0, 3.0, 4.0],
144
+ "B": [0.0, 1.0, 0.0, 1.0, 0.0],
145
+ "C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
146
+ "D": pd.date_range("20130101", periods=5),
147
+ }
148
+ ),
149
+ DataFrame(range(5), index=pd.date_range("2020-01-01", periods=5)),
150
+ Series(range(5), index=pd.date_range("2020-01-01", periods=5)),
151
+ Series(period_range("2020-01-01", periods=10, freq="D")),
152
+ Series(pd.date_range("20130101", periods=3, tz="US/Eastern")),
153
+ ],
154
+ )
155
+ def test_hash_pandas_object(obj, index):
156
+ a = hash_pandas_object(obj, index=index)
157
+ b = hash_pandas_object(obj, index=index)
158
+ tm.assert_series_equal(a, b)
159
+
160
+
161
+ @pytest.mark.parametrize(
162
+ "obj",
163
+ [
164
+ Series([1, 2, 3]),
165
+ Series([1.0, 1.5, 3.2]),
166
+ Series([1.0, 1.5, np.nan]),
167
+ Series([1.0, 1.5, 3.2], index=[1.5, 1.1, 3.3]),
168
+ Series(["a", "b", "c"]),
169
+ Series(["a", np.nan, "c"]),
170
+ Series(["a", None, "c"]),
171
+ Series([True, False, True]),
172
+ DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3]}),
173
+ DataFrame(np.full((10, 4), np.nan)),
174
+ DataFrame(
175
+ {
176
+ "A": [0.0, 1.0, 2.0, 3.0, 4.0],
177
+ "B": [0.0, 1.0, 0.0, 1.0, 0.0],
178
+ "C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
179
+ "D": pd.date_range("20130101", periods=5),
180
+ }
181
+ ),
182
+ DataFrame(range(5), index=pd.date_range("2020-01-01", periods=5)),
183
+ Series(range(5), index=pd.date_range("2020-01-01", periods=5)),
184
+ Series(period_range("2020-01-01", periods=10, freq="D")),
185
+ Series(pd.date_range("20130101", periods=3, tz="US/Eastern")),
186
+ ],
187
+ )
188
+ def test_hash_pandas_object_diff_index_non_empty(obj):
189
+ a = hash_pandas_object(obj, index=True)
190
+ b = hash_pandas_object(obj, index=False)
191
+ assert not (a == b).all()
192
+
193
+
194
+ @pytest.mark.parametrize(
195
+ "obj",
196
+ [
197
+ Index([1, 2, 3]),
198
+ Index([True, False, True]),
199
+ timedelta_range("1 day", periods=2),
200
+ period_range("2020-01-01", freq="D", periods=2),
201
+ MultiIndex.from_product(
202
+ [range(5), ["foo", "bar", "baz"], pd.date_range("20130101", periods=2)]
203
+ ),
204
+ MultiIndex.from_product([pd.CategoricalIndex(list("aabc")), range(3)]),
205
+ ],
206
+ )
207
+ def test_hash_pandas_index(obj, index):
208
+ a = hash_pandas_object(obj, index=index)
209
+ b = hash_pandas_object(obj, index=index)
210
+ tm.assert_series_equal(a, b)
211
+
212
+
213
+ def test_hash_pandas_series(series, index):
214
+ a = hash_pandas_object(series, index=index)
215
+ b = hash_pandas_object(series, index=index)
216
+ tm.assert_series_equal(a, b)
217
+
218
+
219
+ def test_hash_pandas_series_diff_index(series):
220
+ a = hash_pandas_object(series, index=True)
221
+ b = hash_pandas_object(series, index=False)
222
+ assert not (a == b).all()
223
+
224
+
225
+ @pytest.mark.parametrize(
226
+ "obj", [Series([], dtype="float64"), Series([], dtype="object"), Index([])]
227
+ )
228
+ def test_hash_pandas_empty_object(obj, index):
229
+ # These are by-definition the same with
230
+ # or without the index as the data is empty.
231
+ a = hash_pandas_object(obj, index=index)
232
+ b = hash_pandas_object(obj, index=index)
233
+ tm.assert_series_equal(a, b)
234
+
235
+
236
+ @pytest.mark.parametrize(
237
+ "s1",
238
+ [
239
+ Series(["a", "b", "c", "d"]),
240
+ Series([1000, 2000, 3000, 4000]),
241
+ Series(pd.date_range(0, periods=4)),
242
+ ],
243
+ )
244
+ @pytest.mark.parametrize("categorize", [True, False])
245
+ def test_categorical_consistency(s1, categorize):
246
+ # see gh-15143
247
+ #
248
+ # Check that categoricals hash consistent with their values,
249
+ # not codes. This should work for categoricals of any dtype.
250
+ s2 = s1.astype("category").cat.set_categories(s1)
251
+ s3 = s2.cat.set_categories(list(reversed(s1)))
252
+
253
+ # These should all hash identically.
254
+ h1 = hash_pandas_object(s1, categorize=categorize)
255
+ h2 = hash_pandas_object(s2, categorize=categorize)
256
+ h3 = hash_pandas_object(s3, categorize=categorize)
257
+
258
+ tm.assert_series_equal(h1, h2)
259
+ tm.assert_series_equal(h1, h3)
260
+
261
+
262
+ def test_categorical_with_nan_consistency():
263
+ c = pd.Categorical.from_codes(
264
+ [-1, 0, 1, 2, 3, 4], categories=pd.date_range("2012-01-01", periods=5, name="B")
265
+ )
266
+ expected = hash_array(c, categorize=False)
267
+
268
+ c = pd.Categorical.from_codes([-1, 0], categories=[pd.Timestamp("2012-01-01")])
269
+ result = hash_array(c, categorize=False)
270
+
271
+ assert result[0] in expected
272
+ assert result[1] in expected
273
+
274
+
275
+ def test_pandas_errors():
276
+ msg = "Unexpected type for hashing"
277
+ with pytest.raises(TypeError, match=msg):
278
+ hash_pandas_object(pd.Timestamp("20130101"))
279
+
280
+
281
+ def test_hash_keys():
282
+ # Using different hash keys, should have
283
+ # different hashes for the same data.
284
+ #
285
+ # This only matters for object dtypes.
286
+ obj = Series(list("abc"))
287
+
288
+ a = hash_pandas_object(obj, hash_key="9876543210123456")
289
+ b = hash_pandas_object(obj, hash_key="9876543210123465")
290
+
291
+ assert (a != b).all()
292
+
293
+
294
+ def test_df_hash_keys():
295
+ # DataFrame version of the test_hash_keys.
296
+ # https://github.com/pandas-dev/pandas/issues/41404
297
+ obj = DataFrame({"x": np.arange(3), "y": list("abc")})
298
+
299
+ a = hash_pandas_object(obj, hash_key="9876543210123456")
300
+ b = hash_pandas_object(obj, hash_key="9876543210123465")
301
+
302
+ assert (a != b).all()
303
+
304
+
305
+ def test_df_encoding():
306
+ # Check that DataFrame recognizes optional encoding.
307
+ # https://github.com/pandas-dev/pandas/issues/41404
308
+ # https://github.com/pandas-dev/pandas/pull/42049
309
+ obj = DataFrame({"x": np.arange(3), "y": list("a+c")})
310
+
311
+ a = hash_pandas_object(obj, encoding="utf8")
312
+ b = hash_pandas_object(obj, encoding="utf7")
313
+
314
+ # Note that the "+" is encoded as "+-" in utf-7.
315
+ assert a[0] == b[0]
316
+ assert a[1] != b[1]
317
+ assert a[2] == b[2]
318
+
319
+
320
+ def test_invalid_key():
321
+ # This only matters for object dtypes.
322
+ msg = "key should be a 16-byte string encoded"
323
+
324
+ with pytest.raises(ValueError, match=msg):
325
+ hash_pandas_object(Series(list("abc")), hash_key="foo")
326
+
327
+
328
+ def test_already_encoded(index):
329
+ # If already encoded, then ok.
330
+ obj = Series(list("abc")).str.encode("utf8")
331
+ a = hash_pandas_object(obj, index=index)
332
+ b = hash_pandas_object(obj, index=index)
333
+ tm.assert_series_equal(a, b)
334
+
335
+
336
+ def test_alternate_encoding(index):
337
+ obj = Series(list("abc"))
338
+ a = hash_pandas_object(obj, index=index)
339
+ b = hash_pandas_object(obj, index=index)
340
+ tm.assert_series_equal(a, b)
341
+
342
+
343
+ @pytest.mark.parametrize("l_exp", range(8))
344
+ @pytest.mark.parametrize("l_add", [0, 1])
345
+ def test_same_len_hash_collisions(l_exp, l_add):
346
+ length = 2 ** (l_exp + 8) + l_add
347
+ idx = np.array([str(i) for i in range(length)], dtype=object)
348
+
349
+ result = hash_array(idx, "utf8")
350
+ assert not result[0] == result[1]
351
+
352
+
353
+ def test_hash_collisions():
354
+ # Hash collisions are bad.
355
+ #
356
+ # https://github.com/pandas-dev/pandas/issues/14711#issuecomment-264885726
357
+ hashes = [
358
+ "Ingrid-9Z9fKIZmkO7i7Cn51Li34pJm44fgX6DYGBNj3VPlOH50m7HnBlPxfIwFMrcNJNMP6PSgLmwWnInciMWrCSAlLEvt7JkJl4IxiMrVbXSa8ZQoVaq5xoQPjltuJEfwdNlO6jo8qRRHvD8sBEBMQASrRa6TsdaPTPCBo3nwIBpE7YzzmyH0vMBhjQZLx1aCT7faSEx7PgFxQhHdKFWROcysamgy9iVj8DO2Fmwg1NNl93rIAqC3mdqfrCxrzfvIY8aJdzin2cHVzy3QUJxZgHvtUtOLxoqnUHsYbNTeq0xcLXpTZEZCxD4PGubIuCNf32c33M7HFsnjWSEjE2yVdWKhmSVodyF8hFYVmhYnMCztQnJrt3O8ZvVRXd5IKwlLexiSp4h888w7SzAIcKgc3g5XQJf6MlSMftDXm9lIsE1mJNiJEv6uY6pgvC3fUPhatlR5JPpVAHNSbSEE73MBzJrhCAbOLXQumyOXigZuPoME7QgJcBalliQol7YZ9",
359
+ "Tim-b9MddTxOWW2AT1Py6vtVbZwGAmYCjbp89p8mxsiFoVX4FyDOF3wFiAkyQTUgwg9sVqVYOZo09Dh1AzhFHbgij52ylF0SEwgzjzHH8TGY8Lypart4p4onnDoDvVMBa0kdthVGKl6K0BDVGzyOXPXKpmnMF1H6rJzqHJ0HywfwS4XYpVwlAkoeNsiicHkJUFdUAhG229INzvIAiJuAHeJDUoyO4DCBqtoZ5TDend6TK7Y914yHlfH3g1WZu5LksKv68VQHJriWFYusW5e6ZZ6dKaMjTwEGuRgdT66iU5nqWTHRH8WSzpXoCFwGcTOwyuqPSe0fTe21DVtJn1FKj9F9nEnR9xOvJUO7E0piCIF4Ad9yAIDY4DBimpsTfKXCu1vdHpKYerzbndfuFe5AhfMduLYZJi5iAw8qKSwR5h86ttXV0Mc0QmXz8dsRvDgxjXSmupPxBggdlqUlC828hXiTPD7am0yETBV0F3bEtvPiNJfremszcV8NcqAoARMe",
360
+ ]
361
+
362
+ # These should be different.
363
+ result1 = hash_array(np.asarray(hashes[0:1], dtype=object), "utf8")
364
+ expected1 = np.array([14963968704024874985], dtype=np.uint64)
365
+ tm.assert_numpy_array_equal(result1, expected1)
366
+
367
+ result2 = hash_array(np.asarray(hashes[1:2], dtype=object), "utf8")
368
+ expected2 = np.array([16428432627716348016], dtype=np.uint64)
369
+ tm.assert_numpy_array_equal(result2, expected2)
370
+
371
+ result = hash_array(np.asarray(hashes, dtype=object), "utf8")
372
+ tm.assert_numpy_array_equal(result, np.concatenate([expected1, expected2], axis=0))
373
+
374
+
375
+ @pytest.mark.parametrize(
376
+ "data, result_data",
377
+ [
378
+ [[tuple("1"), tuple("2")], [10345501319357378243, 8331063931016360761]],
379
+ [[(1,), (2,)], [9408946347443669104, 3278256261030523334]],
380
+ ],
381
+ )
382
+ def test_hash_with_tuple(data, result_data):
383
+ # GH#28969 array containing a tuple raises on call to arr.astype(str)
384
+ # apparently a numpy bug github.com/numpy/numpy/issues/9441
385
+
386
+ df = DataFrame({"data": data})
387
+ result = hash_pandas_object(df)
388
+ expected = Series(result_data, dtype=np.uint64)
389
+ tm.assert_series_equal(result, expected)
390
+
391
+
392
+ def test_hashable_tuple_args():
393
+ # require that the elements of such tuples are themselves hashable
394
+
395
+ df3 = DataFrame(
396
+ {
397
+ "data": [
398
+ (
399
+ 1,
400
+ [],
401
+ ),
402
+ (
403
+ 2,
404
+ {},
405
+ ),
406
+ ]
407
+ }
408
+ )
409
+ with pytest.raises(TypeError, match="unhashable type: 'list'"):
410
+ hash_pandas_object(df3)
411
+
412
+
413
+ def test_hash_object_none_key():
414
+ # https://github.com/pandas-dev/pandas/issues/30887
415
+ result = pd.util.hash_pandas_object(Series(["a", "b"]), hash_key=None)
416
+ expected = Series([4578374827886788867, 17338122309987883691], dtype="uint64")
417
+ tm.assert_series_equal(result, expected)
venv/lib/python3.10/site-packages/pandas/tests/util/test_numba.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ import pandas.util._test_decorators as td
4
+
5
+ from pandas import option_context
6
+
7
+
8
+ @td.skip_if_installed("numba")
9
+ def test_numba_not_installed_option_context():
10
+ with pytest.raises(ImportError, match="Missing optional"):
11
+ with option_context("compute.use_numba", True):
12
+ pass
venv/lib/python3.10/site-packages/pandas/tests/util/test_rewrite_warning.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import warnings
2
+
3
+ import pytest
4
+
5
+ from pandas.util._exceptions import rewrite_warning
6
+
7
+ import pandas._testing as tm
8
+
9
+
10
+ @pytest.mark.parametrize(
11
+ "target_category, target_message, hit",
12
+ [
13
+ (FutureWarning, "Target message", True),
14
+ (FutureWarning, "Target", True),
15
+ (FutureWarning, "get mess", True),
16
+ (FutureWarning, "Missed message", False),
17
+ (DeprecationWarning, "Target message", False),
18
+ ],
19
+ )
20
+ @pytest.mark.parametrize(
21
+ "new_category",
22
+ [
23
+ None,
24
+ DeprecationWarning,
25
+ ],
26
+ )
27
+ def test_rewrite_warning(target_category, target_message, hit, new_category):
28
+ new_message = "Rewritten message"
29
+ if hit:
30
+ expected_category = new_category if new_category else target_category
31
+ expected_message = new_message
32
+ else:
33
+ expected_category = FutureWarning
34
+ expected_message = "Target message"
35
+ with tm.assert_produces_warning(expected_category, match=expected_message):
36
+ with rewrite_warning(
37
+ target_message, target_category, new_message, new_category
38
+ ):
39
+ warnings.warn(message="Target message", category=FutureWarning)
venv/lib/python3.10/site-packages/pandas/tests/util/test_shares_memory.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas.util._test_decorators as td
2
+
3
+ import pandas as pd
4
+ import pandas._testing as tm
5
+
6
+
7
+ def test_shares_memory_interval():
8
+ obj = pd.interval_range(1, 5)
9
+
10
+ assert tm.shares_memory(obj, obj)
11
+ assert tm.shares_memory(obj, obj._data)
12
+ assert tm.shares_memory(obj, obj[::-1])
13
+ assert tm.shares_memory(obj, obj[:2])
14
+
15
+ assert not tm.shares_memory(obj, obj._data.copy())
16
+
17
+
18
+ @td.skip_if_no("pyarrow")
19
+ def test_shares_memory_string():
20
+ # GH#55823
21
+ import pyarrow as pa
22
+
23
+ obj = pd.array(["a", "b"], dtype="string[pyarrow]")
24
+ assert tm.shares_memory(obj, obj)
25
+
26
+ obj = pd.array(["a", "b"], dtype="string[pyarrow_numpy]")
27
+ assert tm.shares_memory(obj, obj)
28
+
29
+ obj = pd.array(["a", "b"], dtype=pd.ArrowDtype(pa.string()))
30
+ assert tm.shares_memory(obj, obj)
venv/lib/python3.10/site-packages/pandas/tests/util/test_show_versions.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import re
4
+
5
+ from pandas.util._print_versions import (
6
+ _get_dependency_info,
7
+ _get_sys_info,
8
+ )
9
+
10
+ import pandas as pd
11
+
12
+
13
+ def test_show_versions(tmpdir):
14
+ # GH39701
15
+ as_json = os.path.join(tmpdir, "test_output.json")
16
+
17
+ pd.show_versions(as_json=as_json)
18
+
19
+ with open(as_json, encoding="utf-8") as fd:
20
+ # check if file output is valid JSON, will raise an exception if not
21
+ result = json.load(fd)
22
+
23
+ # Basic check that each version element is found in output
24
+ expected = {
25
+ "system": _get_sys_info(),
26
+ "dependencies": _get_dependency_info(),
27
+ }
28
+
29
+ assert result == expected
30
+
31
+
32
+ def test_show_versions_console_json(capsys):
33
+ # GH39701
34
+ pd.show_versions(as_json=True)
35
+ stdout = capsys.readouterr().out
36
+
37
+ # check valid json is printed to the console if as_json is True
38
+ result = json.loads(stdout)
39
+
40
+ # Basic check that each version element is found in output
41
+ expected = {
42
+ "system": _get_sys_info(),
43
+ "dependencies": _get_dependency_info(),
44
+ }
45
+
46
+ assert result == expected
47
+
48
+
49
+ def test_show_versions_console(capsys):
50
+ # gh-32041
51
+ # gh-32041
52
+ pd.show_versions(as_json=False)
53
+ result = capsys.readouterr().out
54
+
55
+ # check header
56
+ assert "INSTALLED VERSIONS" in result
57
+
58
+ # check full commit hash
59
+ assert re.search(r"commit\s*:\s[0-9a-f]{40}\n", result)
60
+
61
+ # check required dependency
62
+ # 2020-12-09 npdev has "dirty" in the tag
63
+ # 2022-05-25 npdev released with RC wo/ "dirty".
64
+ # Just ensure we match [0-9]+\..* since npdev version is variable
65
+ assert re.search(r"numpy\s*:\s[0-9]+\..*\n", result)
66
+
67
+ # check optional dependency
68
+ assert re.search(r"pyarrow\s*:\s([0-9]+.*|None)\n", result)
69
+
70
+
71
+ def test_json_output_match(capsys, tmpdir):
72
+ # GH39701
73
+ pd.show_versions(as_json=True)
74
+ result_console = capsys.readouterr().out
75
+
76
+ out_path = os.path.join(tmpdir, "test_json.json")
77
+ pd.show_versions(as_json=out_path)
78
+ with open(out_path, encoding="utf-8") as out_fd:
79
+ result_file = out_fd.read()
80
+
81
+ assert result_console == result_file
venv/lib/python3.10/site-packages/pandas/tests/util/test_util.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import pytest
4
+
5
+ from pandas import (
6
+ array,
7
+ compat,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ def test_numpy_err_state_is_default():
13
+ expected = {"over": "warn", "divide": "warn", "invalid": "warn", "under": "ignore"}
14
+ import numpy as np
15
+
16
+ # The error state should be unchanged after that import.
17
+ assert np.geterr() == expected
18
+
19
+
20
+ def test_convert_rows_list_to_csv_str():
21
+ rows_list = ["aaa", "bbb", "ccc"]
22
+ ret = tm.convert_rows_list_to_csv_str(rows_list)
23
+
24
+ if compat.is_platform_windows():
25
+ expected = "aaa\r\nbbb\r\nccc\r\n"
26
+ else:
27
+ expected = "aaa\nbbb\nccc\n"
28
+
29
+ assert ret == expected
30
+
31
+
32
+ @pytest.mark.parametrize("strict_data_files", [True, False])
33
+ def test_datapath_missing(datapath):
34
+ with pytest.raises(ValueError, match="Could not find file"):
35
+ datapath("not_a_file")
36
+
37
+
38
+ def test_datapath(datapath):
39
+ args = ("io", "data", "csv", "iris.csv")
40
+
41
+ result = datapath(*args)
42
+ expected = os.path.join(os.path.dirname(os.path.dirname(__file__)), *args)
43
+
44
+ assert result == expected
45
+
46
+
47
+ def test_external_error_raised():
48
+ with tm.external_error_raised(TypeError):
49
+ raise TypeError("Should not check this error message, so it will pass")
50
+
51
+
52
+ def test_is_sorted():
53
+ arr = array([1, 2, 3], dtype="Int64")
54
+ tm.assert_is_sorted(arr)
55
+
56
+ arr = array([4, 2, 3], dtype="Int64")
57
+ with pytest.raises(AssertionError, match="ExtensionArray are different"):
58
+ tm.assert_is_sorted(arr)
venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_args.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas.util._validators import validate_args
4
+
5
+
6
+ @pytest.fixture
7
+ def _fname():
8
+ return "func"
9
+
10
+
11
+ def test_bad_min_fname_arg_count(_fname):
12
+ msg = "'max_fname_arg_count' must be non-negative"
13
+
14
+ with pytest.raises(ValueError, match=msg):
15
+ validate_args(_fname, (None,), -1, "foo")
16
+
17
+
18
+ def test_bad_arg_length_max_value_single(_fname):
19
+ args = (None, None)
20
+ compat_args = ("foo",)
21
+
22
+ min_fname_arg_count = 0
23
+ max_length = len(compat_args) + min_fname_arg_count
24
+ actual_length = len(args) + min_fname_arg_count
25
+ msg = (
26
+ rf"{_fname}\(\) takes at most {max_length} "
27
+ rf"argument \({actual_length} given\)"
28
+ )
29
+
30
+ with pytest.raises(TypeError, match=msg):
31
+ validate_args(_fname, args, min_fname_arg_count, compat_args)
32
+
33
+
34
+ def test_bad_arg_length_max_value_multiple(_fname):
35
+ args = (None, None)
36
+ compat_args = {"foo": None}
37
+
38
+ min_fname_arg_count = 2
39
+ max_length = len(compat_args) + min_fname_arg_count
40
+ actual_length = len(args) + min_fname_arg_count
41
+ msg = (
42
+ rf"{_fname}\(\) takes at most {max_length} "
43
+ rf"arguments \({actual_length} given\)"
44
+ )
45
+
46
+ with pytest.raises(TypeError, match=msg):
47
+ validate_args(_fname, args, min_fname_arg_count, compat_args)
48
+
49
+
50
+ @pytest.mark.parametrize("i", range(1, 3))
51
+ def test_not_all_defaults(i, _fname):
52
+ bad_arg = "foo"
53
+ msg = (
54
+ f"the '{bad_arg}' parameter is not supported "
55
+ rf"in the pandas implementation of {_fname}\(\)"
56
+ )
57
+
58
+ compat_args = {"foo": 2, "bar": -1, "baz": 3}
59
+ arg_vals = (1, -1, 3)
60
+
61
+ with pytest.raises(ValueError, match=msg):
62
+ validate_args(_fname, arg_vals[:i], 2, compat_args)
63
+
64
+
65
+ def test_validation(_fname):
66
+ # No exceptions should be raised.
67
+ validate_args(_fname, (None,), 2, {"out": None})
68
+
69
+ compat_args = {"axis": 1, "out": None}
70
+ validate_args(_fname, (1, None), 2, compat_args)
venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_args_and_kwargs.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas.util._validators import validate_args_and_kwargs
4
+
5
+
6
+ @pytest.fixture
7
+ def _fname():
8
+ return "func"
9
+
10
+
11
+ def test_invalid_total_length_max_length_one(_fname):
12
+ compat_args = ("foo",)
13
+ kwargs = {"foo": "FOO"}
14
+ args = ("FoO", "BaZ")
15
+
16
+ min_fname_arg_count = 0
17
+ max_length = len(compat_args) + min_fname_arg_count
18
+ actual_length = len(kwargs) + len(args) + min_fname_arg_count
19
+
20
+ msg = (
21
+ rf"{_fname}\(\) takes at most {max_length} "
22
+ rf"argument \({actual_length} given\)"
23
+ )
24
+
25
+ with pytest.raises(TypeError, match=msg):
26
+ validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args)
27
+
28
+
29
+ def test_invalid_total_length_max_length_multiple(_fname):
30
+ compat_args = ("foo", "bar", "baz")
31
+ kwargs = {"foo": "FOO", "bar": "BAR"}
32
+ args = ("FoO", "BaZ")
33
+
34
+ min_fname_arg_count = 2
35
+ max_length = len(compat_args) + min_fname_arg_count
36
+ actual_length = len(kwargs) + len(args) + min_fname_arg_count
37
+
38
+ msg = (
39
+ rf"{_fname}\(\) takes at most {max_length} "
40
+ rf"arguments \({actual_length} given\)"
41
+ )
42
+
43
+ with pytest.raises(TypeError, match=msg):
44
+ validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args)
45
+
46
+
47
+ @pytest.mark.parametrize("args,kwargs", [((), {"foo": -5, "bar": 2}), ((-5, 2), {})])
48
+ def test_missing_args_or_kwargs(args, kwargs, _fname):
49
+ bad_arg = "bar"
50
+ min_fname_arg_count = 2
51
+
52
+ compat_args = {"foo": -5, bad_arg: 1}
53
+
54
+ msg = (
55
+ rf"the '{bad_arg}' parameter is not supported "
56
+ rf"in the pandas implementation of {_fname}\(\)"
57
+ )
58
+
59
+ with pytest.raises(ValueError, match=msg):
60
+ validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args)
61
+
62
+
63
+ def test_duplicate_argument(_fname):
64
+ min_fname_arg_count = 2
65
+
66
+ compat_args = {"foo": None, "bar": None, "baz": None}
67
+ kwargs = {"foo": None, "bar": None}
68
+ args = (None,) # duplicate value for "foo"
69
+
70
+ msg = rf"{_fname}\(\) got multiple values for keyword argument 'foo'"
71
+
72
+ with pytest.raises(TypeError, match=msg):
73
+ validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args)
74
+
75
+
76
+ def test_validation(_fname):
77
+ # No exceptions should be raised.
78
+ compat_args = {"foo": 1, "bar": None, "baz": -2}
79
+ kwargs = {"baz": -2}
80
+
81
+ args = (1, None)
82
+ min_fname_arg_count = 2
83
+
84
+ validate_args_and_kwargs(_fname, args, kwargs, min_fname_arg_count, compat_args)
venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_inclusive.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas.util._validators import validate_inclusive
5
+
6
+ import pandas as pd
7
+
8
+
9
+ @pytest.mark.parametrize(
10
+ "invalid_inclusive",
11
+ (
12
+ "ccc",
13
+ 2,
14
+ object(),
15
+ None,
16
+ np.nan,
17
+ pd.NA,
18
+ pd.DataFrame(),
19
+ ),
20
+ )
21
+ def test_invalid_inclusive(invalid_inclusive):
22
+ with pytest.raises(
23
+ ValueError,
24
+ match="Inclusive has to be either 'both', 'neither', 'left' or 'right'",
25
+ ):
26
+ validate_inclusive(invalid_inclusive)
27
+
28
+
29
+ @pytest.mark.parametrize(
30
+ "valid_inclusive, expected_tuple",
31
+ (
32
+ ("left", (True, False)),
33
+ ("right", (False, True)),
34
+ ("both", (True, True)),
35
+ ("neither", (False, False)),
36
+ ),
37
+ )
38
+ def test_valid_inclusive(valid_inclusive, expected_tuple):
39
+ resultant_tuple = validate_inclusive(valid_inclusive)
40
+ assert expected_tuple == resultant_tuple
venv/lib/python3.10/site-packages/pandas/tests/util/test_validate_kwargs.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas.util._validators import (
4
+ validate_bool_kwarg,
5
+ validate_kwargs,
6
+ )
7
+
8
+
9
+ @pytest.fixture
10
+ def _fname():
11
+ return "func"
12
+
13
+
14
+ def test_bad_kwarg(_fname):
15
+ good_arg = "f"
16
+ bad_arg = good_arg + "o"
17
+
18
+ compat_args = {good_arg: "foo", bad_arg + "o": "bar"}
19
+ kwargs = {good_arg: "foo", bad_arg: "bar"}
20
+
21
+ msg = rf"{_fname}\(\) got an unexpected keyword argument '{bad_arg}'"
22
+
23
+ with pytest.raises(TypeError, match=msg):
24
+ validate_kwargs(_fname, kwargs, compat_args)
25
+
26
+
27
+ @pytest.mark.parametrize("i", range(1, 3))
28
+ def test_not_all_none(i, _fname):
29
+ bad_arg = "foo"
30
+ msg = (
31
+ rf"the '{bad_arg}' parameter is not supported "
32
+ rf"in the pandas implementation of {_fname}\(\)"
33
+ )
34
+
35
+ compat_args = {"foo": 1, "bar": "s", "baz": None}
36
+
37
+ kwarg_keys = ("foo", "bar", "baz")
38
+ kwarg_vals = (2, "s", None)
39
+
40
+ kwargs = dict(zip(kwarg_keys[:i], kwarg_vals[:i]))
41
+
42
+ with pytest.raises(ValueError, match=msg):
43
+ validate_kwargs(_fname, kwargs, compat_args)
44
+
45
+
46
+ def test_validation(_fname):
47
+ # No exceptions should be raised.
48
+ compat_args = {"f": None, "b": 1, "ba": "s"}
49
+
50
+ kwargs = {"f": None, "b": 1}
51
+ validate_kwargs(_fname, kwargs, compat_args)
52
+
53
+
54
+ @pytest.mark.parametrize("name", ["inplace", "copy"])
55
+ @pytest.mark.parametrize("value", [1, "True", [1, 2, 3], 5.0])
56
+ def test_validate_bool_kwarg_fail(name, value):
57
+ msg = (
58
+ f'For argument "{name}" expected type bool, '
59
+ f"received type {type(value).__name__}"
60
+ )
61
+
62
+ with pytest.raises(ValueError, match=msg):
63
+ validate_bool_kwarg(value, name)
64
+
65
+
66
+ @pytest.mark.parametrize("name", ["inplace", "copy"])
67
+ @pytest.mark.parametrize("value", [True, False, None])
68
+ def test_validate_bool_kwarg(name, value):
69
+ assert validate_bool_kwarg(value, name) == value
venv/lib/python3.10/site-packages/pandas/tests/window/__init__.py ADDED
File without changes
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (187 Bytes). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/conftest.cpython-310.pyc ADDED
Binary file (3.47 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_api.cpython-310.pyc ADDED
Binary file (11.7 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_apply.cpython-310.pyc ADDED
Binary file (11 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_base_indexer.cpython-310.pyc ADDED
Binary file (13.9 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_cython_aggregations.cpython-310.pyc ADDED
Binary file (3.52 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_dtypes.cpython-310.pyc ADDED
Binary file (4.06 kB). View file
 
venv/lib/python3.10/site-packages/pandas/tests/window/__pycache__/test_ewm.cpython-310.pyc ADDED
Binary file (18.7 kB). View file