Skip to content

Commit cb2fe03

Browse files
SaturnFromTitanjreback
authored andcommitted
Fixed test util imports in pandas/tests/util (#29278)
1 parent 53f81a1 commit cb2fe03

8 files changed

+106
-102
lines changed

pandas/tests/util/test_assert_almost_equal.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
from pandas import DataFrame, Index, Series, Timestamp
5-
from pandas.util.testing import assert_almost_equal
5+
import pandas.util.testing as tm
66

77

88
def _assert_almost_equal_both(a, b, **kwargs):
@@ -18,10 +18,10 @@ def _assert_almost_equal_both(a, b, **kwargs):
1818
b : object
1919
The second object to compare.
2020
kwargs : dict
21-
The arguments passed to `assert_almost_equal`.
21+
The arguments passed to `tm.assert_almost_equal`.
2222
"""
23-
assert_almost_equal(a, b, **kwargs)
24-
assert_almost_equal(b, a, **kwargs)
23+
tm.assert_almost_equal(a, b, **kwargs)
24+
tm.assert_almost_equal(b, a, **kwargs)
2525

2626

2727
def _assert_not_almost_equal(a, b, **kwargs):
@@ -35,10 +35,10 @@ def _assert_not_almost_equal(a, b, **kwargs):
3535
b : object
3636
The second object to compare.
3737
kwargs : dict
38-
The arguments passed to `assert_almost_equal`.
38+
The arguments passed to `tm.assert_almost_equal`.
3939
"""
4040
try:
41-
assert_almost_equal(a, b, **kwargs)
41+
tm.assert_almost_equal(a, b, **kwargs)
4242
msg = (
4343
"{a} and {b} were approximately equal when they shouldn't have been"
4444
).format(a=a, b=b)
@@ -240,7 +240,7 @@ def test_assert_almost_equal_value_mismatch():
240240
msg = "expected 2\\.00000 but got 1\\.00000, with decimal 5"
241241

242242
with pytest.raises(AssertionError, match=msg):
243-
assert_almost_equal(1, 2)
243+
tm.assert_almost_equal(1, 2)
244244

245245

246246
@pytest.mark.parametrize(
@@ -257,7 +257,7 @@ def test_assert_almost_equal_class_mismatch(a, b, klass1, klass2):
257257
)
258258

259259
with pytest.raises(AssertionError, match=msg):
260-
assert_almost_equal(a, b)
260+
tm.assert_almost_equal(a, b)
261261

262262

263263
def test_assert_almost_equal_value_mismatch1():
@@ -268,7 +268,7 @@ def test_assert_almost_equal_value_mismatch1():
268268
\\[right\\]: \\[1\\.0, nan, 3\\.0\\]"""
269269

270270
with pytest.raises(AssertionError, match=msg):
271-
assert_almost_equal(np.array([np.nan, 2, 3]), np.array([1, np.nan, 3]))
271+
tm.assert_almost_equal(np.array([np.nan, 2, 3]), np.array([1, np.nan, 3]))
272272

273273

274274
def test_assert_almost_equal_value_mismatch2():
@@ -279,7 +279,7 @@ def test_assert_almost_equal_value_mismatch2():
279279
\\[right\\]: \\[1, 3\\]"""
280280

281281
with pytest.raises(AssertionError, match=msg):
282-
assert_almost_equal(np.array([1, 2]), np.array([1, 3]))
282+
tm.assert_almost_equal(np.array([1, 2]), np.array([1, 3]))
283283

284284

285285
def test_assert_almost_equal_value_mismatch3():
@@ -290,7 +290,7 @@ def test_assert_almost_equal_value_mismatch3():
290290
\\[right\\]: \\[\\[1, 3\\], \\[3, 4\\], \\[5, 6\\]\\]"""
291291

292292
with pytest.raises(AssertionError, match=msg):
293-
assert_almost_equal(
293+
tm.assert_almost_equal(
294294
np.array([[1, 2], [3, 4], [5, 6]]), np.array([[1, 3], [3, 4], [5, 6]])
295295
)
296296

@@ -303,7 +303,7 @@ def test_assert_almost_equal_value_mismatch4():
303303
\\[right\\]: \\[\\[1, 3\\], \\[3, 4\\]\\]"""
304304

305305
with pytest.raises(AssertionError, match=msg):
306-
assert_almost_equal(np.array([[1, 2], [3, 4]]), np.array([[1, 3], [3, 4]]))
306+
tm.assert_almost_equal(np.array([[1, 2], [3, 4]]), np.array([[1, 3], [3, 4]]))
307307

308308

309309
def test_assert_almost_equal_shape_mismatch_override():
@@ -313,7 +313,7 @@ def test_assert_almost_equal_shape_mismatch_override():
313313
\\[left\\]: \\(2L*,\\)
314314
\\[right\\]: \\(3L*,\\)"""
315315
with pytest.raises(AssertionError, match=msg):
316-
assert_almost_equal(np.array([1, 2]), np.array([3, 4, 5]), obj="Index")
316+
tm.assert_almost_equal(np.array([1, 2]), np.array([3, 4, 5]), obj="Index")
317317

318318

319319
def test_assert_almost_equal_unicode():
@@ -325,7 +325,7 @@ def test_assert_almost_equal_unicode():
325325
\\[right\\]: \\[á, à, å\\]"""
326326

327327
with pytest.raises(AssertionError, match=msg):
328-
assert_almost_equal(np.array(["á", "à", "ä"]), np.array(["á", "à", "å"]))
328+
tm.assert_almost_equal(np.array(["á", "à", "ä"]), np.array(["á", "à", "å"]))
329329

330330

331331
def test_assert_almost_equal_timestamp():
@@ -339,7 +339,7 @@ def test_assert_almost_equal_timestamp():
339339
\\[right\\]: \\[2011-01-01 00:00:00, 2011-01-02 00:00:00\\]"""
340340

341341
with pytest.raises(AssertionError, match=msg):
342-
assert_almost_equal(a, b)
342+
tm.assert_almost_equal(a, b)
343343

344344

345345
def test_assert_almost_equal_iterable_length_mismatch():
@@ -350,7 +350,7 @@ def test_assert_almost_equal_iterable_length_mismatch():
350350
\\[right\\]: 3"""
351351

352352
with pytest.raises(AssertionError, match=msg):
353-
assert_almost_equal([1, 2], [3, 4, 5])
353+
tm.assert_almost_equal([1, 2], [3, 4, 5])
354354

355355

356356
def test_assert_almost_equal_iterable_values_mismatch():
@@ -361,4 +361,4 @@ def test_assert_almost_equal_iterable_values_mismatch():
361361
\\[right\\]: \\[1, 3\\]"""
362362

363363
with pytest.raises(AssertionError, match=msg):
364-
assert_almost_equal([1, 2], [1, 3])
364+
tm.assert_almost_equal([1, 2], [1, 3])

pandas/tests/util/test_assert_categorical_equal.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import pytest
22

33
from pandas import Categorical
4-
from pandas.util.testing import assert_categorical_equal
4+
import pandas.util.testing as tm
55

66

77
@pytest.mark.parametrize(
88
"c",
99
[Categorical([1, 2, 3, 4]), Categorical([1, 2, 3, 4], categories=[1, 2, 3, 4, 5])],
1010
)
1111
def test_categorical_equal(c):
12-
assert_categorical_equal(c, c)
12+
tm.assert_categorical_equal(c, c)
1313

1414

1515
@pytest.mark.parametrize("check_category_order", [True, False])
@@ -25,9 +25,9 @@ def test_categorical_equal_order_mismatch(check_category_order):
2525
\\[left\\]: Int64Index\\(\\[1, 2, 3, 4\\], dtype='int64'\\)
2626
\\[right\\]: Int64Index\\(\\[4, 3, 2, 1\\], dtype='int64'\\)"""
2727
with pytest.raises(AssertionError, match=msg):
28-
assert_categorical_equal(c1, c2, **kwargs)
28+
tm.assert_categorical_equal(c1, c2, **kwargs)
2929
else:
30-
assert_categorical_equal(c1, c2, **kwargs)
30+
tm.assert_categorical_equal(c1, c2, **kwargs)
3131

3232

3333
def test_categorical_equal_categories_mismatch():
@@ -41,7 +41,7 @@ def test_categorical_equal_categories_mismatch():
4141
c2 = Categorical([1, 2, 3, 5])
4242

4343
with pytest.raises(AssertionError, match=msg):
44-
assert_categorical_equal(c1, c2)
44+
tm.assert_categorical_equal(c1, c2)
4545

4646

4747
def test_categorical_equal_codes_mismatch():
@@ -56,7 +56,7 @@ def test_categorical_equal_codes_mismatch():
5656
c2 = Categorical([1, 2, 3, 4], categories=categories)
5757

5858
with pytest.raises(AssertionError, match=msg):
59-
assert_categorical_equal(c1, c2)
59+
tm.assert_categorical_equal(c1, c2)
6060

6161

6262
def test_categorical_equal_ordered_mismatch():
@@ -71,7 +71,7 @@ def test_categorical_equal_ordered_mismatch():
7171
c2 = Categorical(data, ordered=True)
7272

7373
with pytest.raises(AssertionError, match=msg):
74-
assert_categorical_equal(c1, c2)
74+
tm.assert_categorical_equal(c1, c2)
7575

7676

7777
@pytest.mark.parametrize("obj", ["index", "foo", "pandas"])
@@ -89,4 +89,4 @@ def test_categorical_equal_object_override(obj):
8989
c2 = Categorical(data, ordered=True)
9090

9191
with pytest.raises(AssertionError, match=msg):
92-
assert_categorical_equal(c1, c2, obj=obj)
92+
tm.assert_categorical_equal(c1, c2, obj=obj)

pandas/tests/util/test_assert_extension_array_equal.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
from pandas.core.arrays.sparse import SparseArray
5-
from pandas.util.testing import assert_extension_array_equal
5+
import pandas.util.testing as tm
66

77

88
@pytest.mark.parametrize(
@@ -27,9 +27,9 @@ def test_assert_extension_array_equal_not_exact(kwargs):
2727
\\[right\\]: \\[-0\\.17387645482.*, 0\\.341414801642.*\\]"""
2828

2929
with pytest.raises(AssertionError, match=msg):
30-
assert_extension_array_equal(arr1, arr2, **kwargs)
30+
tm.assert_extension_array_equal(arr1, arr2, **kwargs)
3131
else:
32-
assert_extension_array_equal(arr1, arr2, **kwargs)
32+
tm.assert_extension_array_equal(arr1, arr2, **kwargs)
3333

3434

3535
@pytest.mark.parametrize(
@@ -50,9 +50,9 @@ def test_assert_extension_array_equal_less_precise(check_less_precise):
5050
\\[right\\]: \\[0\\.5, 0\\.123457\\]"""
5151

5252
with pytest.raises(AssertionError, match=msg):
53-
assert_extension_array_equal(arr1, arr2, **kwargs)
53+
tm.assert_extension_array_equal(arr1, arr2, **kwargs)
5454
else:
55-
assert_extension_array_equal(arr1, arr2, **kwargs)
55+
tm.assert_extension_array_equal(arr1, arr2, **kwargs)
5656

5757

5858
def test_assert_extension_array_equal_dtype_mismatch(check_dtype):
@@ -71,9 +71,9 @@ def test_assert_extension_array_equal_dtype_mismatch(check_dtype):
7171
\\[right\\]: Sparse\\[int32, 0\\]"""
7272

7373
with pytest.raises(AssertionError, match=msg):
74-
assert_extension_array_equal(arr1, arr2, **kwargs)
74+
tm.assert_extension_array_equal(arr1, arr2, **kwargs)
7575
else:
76-
assert_extension_array_equal(arr1, arr2, **kwargs)
76+
tm.assert_extension_array_equal(arr1, arr2, **kwargs)
7777

7878

7979
def test_assert_extension_array_equal_missing_values():
@@ -88,7 +88,7 @@ def test_assert_extension_array_equal_missing_values():
8888
\\[right\\]: \\[True, False, False, False\\]"""
8989

9090
with pytest.raises(AssertionError, match=msg):
91-
assert_extension_array_equal(arr1, arr2)
91+
tm.assert_extension_array_equal(arr1, arr2)
9292

9393

9494
@pytest.mark.parametrize("side", ["left", "right"])
@@ -104,4 +104,4 @@ def test_assert_extension_array_equal_non_extension_array(side):
104104
)
105105

106106
with pytest.raises(AssertionError, match=msg):
107-
assert_extension_array_equal(*args)
107+
tm.assert_extension_array_equal(*args)

pandas/tests/util/test_assert_frame_equal.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from pandas import DataFrame
4-
from pandas.util.testing import assert_frame_equal
4+
import pandas.util.testing as tm
55

66

77
@pytest.fixture(params=[True, False])
@@ -27,10 +27,10 @@ def _assert_frame_equal_both(a, b, **kwargs):
2727
b : DataFrame
2828
The second DataFrame to compare.
2929
kwargs : dict
30-
The arguments passed to `assert_frame_equal`.
30+
The arguments passed to `tm.assert_frame_equal`.
3131
"""
32-
assert_frame_equal(a, b, **kwargs)
33-
assert_frame_equal(b, a, **kwargs)
32+
tm.assert_frame_equal(a, b, **kwargs)
33+
tm.assert_frame_equal(b, a, **kwargs)
3434

3535

3636
def _assert_not_frame_equal(a, b, **kwargs):
@@ -44,10 +44,10 @@ def _assert_not_frame_equal(a, b, **kwargs):
4444
b : DataFrame
4545
The second DataFrame to compare.
4646
kwargs : dict
47-
The arguments passed to `assert_frame_equal`.
47+
The arguments passed to `tm.assert_frame_equal`.
4848
"""
4949
try:
50-
assert_frame_equal(a, b, **kwargs)
50+
tm.assert_frame_equal(a, b, **kwargs)
5151
msg = "The two DataFrames were equal when they shouldn't have been"
5252

5353
pytest.fail(msg=msg)
@@ -68,7 +68,7 @@ def _assert_not_frame_equal_both(a, b, **kwargs):
6868
b : DataFrame
6969
The second DataFrame to compare.
7070
kwargs : dict
71-
The arguments passed to `assert_frame_equal`.
71+
The arguments passed to `tm.assert_frame_equal`.
7272
"""
7373
_assert_not_frame_equal(a, b, **kwargs)
7474
_assert_not_frame_equal(b, a, **kwargs)
@@ -82,7 +82,7 @@ def test_frame_equal_row_order_mismatch(check_like, obj_fixture):
8282
if not check_like: # Do not ignore row-column orderings.
8383
msg = "{obj}.index are different".format(obj=obj_fixture)
8484
with pytest.raises(AssertionError, match=msg):
85-
assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture)
85+
tm.assert_frame_equal(df1, df2, check_like=check_like, obj=obj_fixture)
8686
else:
8787
_assert_frame_equal_both(df1, df2, check_like=check_like, obj=obj_fixture)
8888

@@ -98,7 +98,7 @@ def test_frame_equal_shape_mismatch(df1, df2, obj_fixture):
9898
msg = "{obj} are different".format(obj=obj_fixture)
9999

100100
with pytest.raises(AssertionError, match=msg):
101-
assert_frame_equal(df1, df2, obj=obj_fixture)
101+
tm.assert_frame_equal(df1, df2, obj=obj_fixture)
102102

103103

104104
@pytest.mark.parametrize(
@@ -127,9 +127,9 @@ def test_frame_equal_index_dtype_mismatch(df1, df2, msg, check_index_type):
127127

128128
if check_index_type:
129129
with pytest.raises(AssertionError, match=msg):
130-
assert_frame_equal(df1, df2, **kwargs)
130+
tm.assert_frame_equal(df1, df2, **kwargs)
131131
else:
132-
assert_frame_equal(df1, df2, **kwargs)
132+
tm.assert_frame_equal(df1, df2, **kwargs)
133133

134134

135135
def test_empty_dtypes(check_dtype):
@@ -143,9 +143,9 @@ def test_empty_dtypes(check_dtype):
143143
if check_dtype:
144144
msg = r"Attributes of DataFrame\..* are different"
145145
with pytest.raises(AssertionError, match=msg):
146-
assert_frame_equal(df1, df2, **kwargs)
146+
tm.assert_frame_equal(df1, df2, **kwargs)
147147
else:
148-
assert_frame_equal(df1, df2, **kwargs)
148+
tm.assert_frame_equal(df1, df2, **kwargs)
149149

150150

151151
def test_frame_equal_index_mismatch(obj_fixture):
@@ -161,7 +161,7 @@ def test_frame_equal_index_mismatch(obj_fixture):
161161
df2 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "d"])
162162

163163
with pytest.raises(AssertionError, match=msg):
164-
assert_frame_equal(df1, df2, obj=obj_fixture)
164+
tm.assert_frame_equal(df1, df2, obj=obj_fixture)
165165

166166

167167
def test_frame_equal_columns_mismatch(obj_fixture):
@@ -177,7 +177,7 @@ def test_frame_equal_columns_mismatch(obj_fixture):
177177
df2 = DataFrame({"A": [1, 2, 3], "b": [4, 5, 6]}, index=["a", "b", "c"])
178178

179179
with pytest.raises(AssertionError, match=msg):
180-
assert_frame_equal(df1, df2, obj=obj_fixture)
180+
tm.assert_frame_equal(df1, df2, obj=obj_fixture)
181181

182182

183183
def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture):
@@ -193,7 +193,7 @@ def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture):
193193
df2 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 7]})
194194

195195
with pytest.raises(AssertionError, match=msg):
196-
assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture)
196+
tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture)
197197

198198

199199
@pytest.mark.parametrize(
@@ -222,8 +222,8 @@ def test_frame_equal_block_mismatch(by_blocks_fixture, obj_fixture):
222222
def test_frame_equal_unicode(df1, df2, msg, by_blocks_fixture, obj_fixture):
223223
# see gh-20503
224224
#
225-
# Test ensures that `assert_frame_equals` raises the right exception
225+
# Test ensures that `tm.assert_frame_equals` raises the right exception
226226
# when comparing DataFrames containing differing unicode objects.
227227
msg = msg.format(obj=obj_fixture)
228228
with pytest.raises(AssertionError, match=msg):
229-
assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture)
229+
tm.assert_frame_equal(df1, df2, by_blocks=by_blocks_fixture, obj=obj_fixture)

0 commit comments

Comments
 (0)