Skip to content

Commit 3ea783e

Browse files
authored
TST: nan->NA in non-construction tests (#62021)
1 parent ff2b77c commit 3ea783e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+197
-185
lines changed

pandas/tests/arrays/categorical/test_astype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
from pandas import (
5+
NA,
56
Categorical,
67
CategoricalDtype,
78
CategoricalIndex,
@@ -34,7 +35,7 @@ def test_astype_nan_to_int(self, cls, values):
3435
array([0, 0], dtype="timedelta64[ns]"),
3536
array([Period("2019"), Period("2020")], dtype="period[Y-DEC]"),
3637
array([Interval(0, 1), Interval(1, 2)], dtype="interval"),
37-
array([1, np.nan], dtype="Int64"),
38+
array([1, NA], dtype="Int64"),
3839
],
3940
)
4041
def test_astype_category_to_extension_dtype(self, expected):

pandas/tests/arrays/floating/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def data_missing(dtype):
3333
Fixture returning array with missing data according to parametrized float
3434
'dtype'.
3535
"""
36-
return pd.array([np.nan, 0.1], dtype=dtype)
36+
return pd.array([pd.NA, 0.1], dtype=dtype)
3737

3838

3939
@pytest.fixture(params=["data", "data_missing"])

pandas/tests/arrays/floating/test_arithmetic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def test_pow_array(dtype):
104104
def test_rpow_one_to_na():
105105
# https://github.com/pandas-dev/pandas/issues/22022
106106
# https://github.com/pandas-dev/pandas/issues/29997
107-
arr = pd.array([np.nan, np.nan], dtype="Float64")
107+
arr = pd.array([pd.NA, pd.NA], dtype="Float64")
108108
result = np.array([1.0, 2.0]) ** arr
109-
expected = pd.array([1.0, np.nan], dtype="Float64")
109+
expected = pd.array([1.0, pd.NA], dtype="Float64")
110110
tm.assert_extension_array_equal(result, expected)
111111

112112

@@ -187,22 +187,22 @@ def test_error_invalid_values(data, all_arithmetic_operators):
187187
def test_cross_type_arithmetic():
188188
df = pd.DataFrame(
189189
{
190-
"A": pd.array([1, 2, np.nan], dtype="Float64"),
191-
"B": pd.array([1, np.nan, 3], dtype="Float32"),
190+
"A": pd.array([1, 2, pd.NA], dtype="Float64"),
191+
"B": pd.array([1, pd.NA, 3], dtype="Float32"),
192192
"C": np.array([1, 2, 3], dtype="float64"),
193193
}
194194
)
195195

196196
result = df.A + df.C
197-
expected = pd.Series([2, 4, np.nan], dtype="Float64")
197+
expected = pd.Series([2, 4, pd.NA], dtype="Float64")
198198
tm.assert_series_equal(result, expected)
199199

200200
result = (df.A + df.C) * 3 == 12
201201
expected = pd.Series([False, True, None], dtype="boolean")
202202
tm.assert_series_equal(result, expected)
203203

204204
result = df.A + df.B
205-
expected = pd.Series([2, np.nan, np.nan], dtype="Float64")
205+
expected = pd.Series([2, pd.NA, pd.NA], dtype="Float64")
206206
tm.assert_series_equal(result, expected)
207207

208208

pandas/tests/arrays/floating/test_construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_floating_array_constructor():
2020
mask = np.array([False, False, False, True], dtype="bool")
2121

2222
result = FloatingArray(values, mask)
23-
expected = pd.array([1, 2, 3, np.nan], dtype="Float64")
23+
expected = pd.array([1, 2, 3, pd.NA], dtype="Float64")
2424
tm.assert_extension_array_equal(result, expected)
2525
tm.assert_numpy_array_equal(result._data, values)
2626
tm.assert_numpy_array_equal(result._mask, mask)

pandas/tests/arrays/floating/test_function.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
1212
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign:RuntimeWarning")
1313
def test_ufuncs_single(ufunc):
14-
a = pd.array([1, 2, -3, np.nan], dtype="Float64")
14+
a = pd.array([1, 2, -3, pd.NA], dtype="Float64")
1515
result = ufunc(a)
1616
expected = pd.array(ufunc(a.astype(float)), dtype="Float64")
1717
tm.assert_extension_array_equal(result, expected)
@@ -24,7 +24,7 @@ def test_ufuncs_single(ufunc):
2424

2525
@pytest.mark.parametrize("ufunc", [np.log, np.exp, np.sin, np.cos, np.sqrt])
2626
def test_ufuncs_single_float(ufunc):
27-
a = pd.array([1.0, 0.2, 3.0, np.nan], dtype="Float64")
27+
a = pd.array([1.0, 0.2, 3.0, pd.NA], dtype="Float64")
2828
with np.errstate(invalid="ignore"):
2929
result = ufunc(a)
3030
expected = pd.array(ufunc(a.astype(float)), dtype="Float64")
@@ -40,7 +40,7 @@ def test_ufuncs_single_float(ufunc):
4040
@pytest.mark.parametrize("ufunc", [np.add, np.subtract])
4141
def test_ufuncs_binary_float(ufunc):
4242
# two FloatingArrays
43-
a = pd.array([1, 0.2, -3, np.nan], dtype="Float64")
43+
a = pd.array([1, 0.2, -3, pd.NA], dtype="Float64")
4444
result = ufunc(a, a)
4545
expected = pd.array(ufunc(a.astype(float), a.astype(float)), dtype="Float64")
4646
tm.assert_extension_array_equal(result, expected)
@@ -88,7 +88,7 @@ def test_ufunc_reduce_raises(values):
8888
],
8989
)
9090
def test_stat_method(pandasmethname, kwargs):
91-
s = pd.Series(data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, np.nan, np.nan], dtype="Float64")
91+
s = pd.Series(data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, pd.NA, pd.NA], dtype="Float64")
9292
pandasmeth = getattr(s, pandasmethname)
9393
result = pandasmeth(**kwargs)
9494
s2 = pd.Series(data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6], dtype="float64")

pandas/tests/arrays/integer/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import numpy as np
21
import pytest
32

43
import pandas as pd
@@ -40,7 +39,7 @@ def data(dtype):
4039
Used to test dtype conversion with and without missing values.
4140
"""
4241
return pd.array(
43-
list(range(8)) + [np.nan] + list(range(10, 98)) + [np.nan] + [99, 100],
42+
list(range(8)) + [pd.NA] + list(range(10, 98)) + [pd.NA] + [99, 100],
4443
dtype=dtype,
4544
)
4645

@@ -53,7 +52,7 @@ def data_missing(dtype):
5352
5453
Used to test dtype conversion with and without missing values.
5554
"""
56-
return pd.array([np.nan, 1], dtype=dtype)
55+
return pd.array([pd.NA, 1], dtype=dtype)
5756

5857

5958
@pytest.fixture(params=["data", "data_missing"])

pandas/tests/arrays/integer/test_arithmetic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def test_pow_array():
154154
def test_rpow_one_to_na():
155155
# https://github.com/pandas-dev/pandas/issues/22022
156156
# https://github.com/pandas-dev/pandas/issues/29997
157-
arr = pd.array([np.nan, np.nan], dtype="Int64")
157+
arr = pd.array([pd.NA, pd.NA], dtype="Int64")
158158
result = np.array([1.0, 2.0]) ** arr
159-
expected = pd.array([1.0, np.nan], dtype="Float64")
159+
expected = pd.array([1.0, pd.NA], dtype="Float64")
160160
tm.assert_extension_array_equal(result, expected)
161161

162162

@@ -243,22 +243,22 @@ def test_arithmetic_conversion(all_arithmetic_operators, other):
243243
def test_cross_type_arithmetic():
244244
df = pd.DataFrame(
245245
{
246-
"A": pd.Series([1, 2, np.nan], dtype="Int64"),
247-
"B": pd.Series([1, np.nan, 3], dtype="UInt8"),
246+
"A": pd.Series([1, 2, pd.NA], dtype="Int64"),
247+
"B": pd.Series([1, pd.NA, 3], dtype="UInt8"),
248248
"C": [1, 2, 3],
249249
}
250250
)
251251

252252
result = df.A + df.C
253-
expected = pd.Series([2, 4, np.nan], dtype="Int64")
253+
expected = pd.Series([2, 4, pd.NA], dtype="Int64")
254254
tm.assert_series_equal(result, expected)
255255

256256
result = (df.A + df.C) * 3 == 12
257257
expected = pd.Series([False, True, None], dtype="boolean")
258258
tm.assert_series_equal(result, expected)
259259

260260
result = df.A + df.B
261-
expected = pd.Series([2, np.nan, np.nan], dtype="Int64")
261+
expected = pd.Series([2, pd.NA, pd.NA], dtype="Int64")
262262
tm.assert_series_equal(result, expected)
263263

264264

pandas/tests/arrays/integer/test_construction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_integer_array_constructor():
7777
mask = np.array([False, False, False, True], dtype="bool")
7878

7979
result = IntegerArray(values, mask)
80-
expected = pd.array([1, 2, 3, np.nan], dtype="Int64")
80+
expected = pd.array([1, 2, 3, pd.NA], dtype="Int64")
8181
tm.assert_extension_array_equal(result, expected)
8282

8383
msg = r".* should be .* numpy array. Use the 'pd.array' function instead"
@@ -191,7 +191,7 @@ def test_to_integer_array_float():
191191

192192
def test_to_integer_array_str():
193193
result = IntegerArray._from_sequence(["1", "2", None], dtype="Int64")
194-
expected = pd.array([1, 2, np.nan], dtype="Int64")
194+
expected = pd.array([1, 2, pd.NA], dtype="Int64")
195195
tm.assert_extension_array_equal(result, expected)
196196

197197
with pytest.raises(

pandas/tests/arrays/integer/test_dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_preserve_dtypes(op):
5252

5353
def test_astype_nansafe():
5454
# see gh-22343
55-
arr = pd.array([np.nan, 1, 2], dtype="Int8")
55+
arr = pd.array([pd.NA, 1, 2], dtype="Int8")
5656
msg = "cannot convert NA to integer"
5757

5858
with pytest.raises(ValueError, match=msg):
@@ -230,7 +230,7 @@ def test_construct_cast_invalid(dtype):
230230
with pytest.raises(TypeError, match=msg):
231231
pd.Series(arr).astype(dtype)
232232

233-
arr = [1.2, 2.3, 3.7, np.nan]
233+
arr = [1.2, 2.3, 3.7, pd.NA]
234234
with pytest.raises(TypeError, match=msg):
235235
pd.array(arr, dtype=dtype)
236236

pandas/tests/arrays/integer/test_function.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
1111
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign:RuntimeWarning")
1212
def test_ufuncs_single_int(ufunc):
13-
a = pd.array([1, 2, -3, np.nan])
13+
a = pd.array([1, 2, -3, pd.NA], dtype="Int64")
1414
result = ufunc(a)
1515
expected = pd.array(ufunc(a.astype(float)), dtype="Int64")
1616
tm.assert_extension_array_equal(result, expected)
@@ -23,7 +23,7 @@ def test_ufuncs_single_int(ufunc):
2323

2424
@pytest.mark.parametrize("ufunc", [np.log, np.exp, np.sin, np.cos, np.sqrt])
2525
def test_ufuncs_single_float(ufunc):
26-
a = pd.array([1, 2, -3, np.nan])
26+
a = pd.array([1, 2, -3, pd.NA], dtype="Int64")
2727
with np.errstate(invalid="ignore"):
2828
result = ufunc(a)
2929
expected = FloatingArray(ufunc(a.astype(float)), mask=a._mask)
@@ -39,7 +39,7 @@ def test_ufuncs_single_float(ufunc):
3939
@pytest.mark.parametrize("ufunc", [np.add, np.subtract])
4040
def test_ufuncs_binary_int(ufunc):
4141
# two IntegerArrays
42-
a = pd.array([1, 2, -3, np.nan])
42+
a = pd.array([1, 2, -3, pd.NA], dtype="Int64")
4343
result = ufunc(a, a)
4444
expected = pd.array(ufunc(a.astype(float), a.astype(float)), dtype="Int64")
4545
tm.assert_extension_array_equal(result, expected)
@@ -99,7 +99,7 @@ def test_ufunc_reduce_raises(values):
9999
],
100100
)
101101
def test_stat_method(pandasmethname, kwargs):
102-
s = pd.Series(data=[1, 2, 3, 4, 5, 6, np.nan, np.nan], dtype="Int64")
102+
s = pd.Series(data=[1, 2, 3, 4, 5, 6, pd.NA, pd.NA], dtype="Int64")
103103
pandasmeth = getattr(s, pandasmethname)
104104
result = pandasmeth(**kwargs)
105105
s2 = pd.Series(data=[1, 2, 3, 4, 5, 6], dtype="Int64")

0 commit comments

Comments
 (0)