Skip to content

Commit 12aa3d3

Browse files
committed
Update NA repr
Closes pandas-dev#30415
1 parent 4a039c6 commit 12aa3d3

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

pandas/_libs/missing.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,7 @@ class NAType(C_NAType):
354354
return NAType._instance
355355

356356
def __repr__(self) -> str:
357-
return "NA"
358-
359-
def __str__(self) -> str:
360-
return "NA"
357+
return "<NA>"
361358

362359
def __bool__(self):
363360
raise TypeError("boolean value of NA is ambiguous")

pandas/io/formats/format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ def _format(x):
12301230
if x is None:
12311231
return "None"
12321232
elif x is NA:
1233-
return "NA"
1233+
return formatter(x)
12341234
elif x is NaT or np.isnat(x):
12351235
return "NaT"
12361236
except (TypeError, ValueError):

pandas/tests/arrays/test_boolean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def test_astype():
335335
tm.assert_numpy_array_equal(result, expected)
336336

337337
result = arr.astype("str")
338-
expected = np.array(["True", "False", "NA"], dtype="object")
338+
expected = np.array(["True", "False", "<NA>"], dtype="object")
339339
tm.assert_numpy_array_equal(result, expected)
340340

341341
# no missing values

pandas/tests/arrays/test_integer.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ def test_repr_dtype(dtype, expected):
9090

9191
def test_repr_array():
9292
result = repr(integer_array([1, None, 3]))
93-
expected = "<IntegerArray>\n[1, NA, 3]\nLength: 3, dtype: Int64"
93+
expected = "<IntegerArray>\n[1, <NA>, 3]\nLength: 3, dtype: Int64"
9494
assert result == expected
9595

9696

9797
def test_repr_array_long():
9898
data = integer_array([1, 2, None] * 1000)
9999
expected = (
100100
"<IntegerArray>\n"
101-
"[ 1, 2, NA, 1, 2, NA, 1, 2, NA, 1,\n"
101+
"[ 1, 2, <NA>, 1, 2, <NA>, 1, 2, <NA>, 1,\n"
102102
" ...\n"
103-
" NA, 1, 2, NA, 1, 2, NA, 1, 2, NA]\n"
103+
" <NA>, 1, 2, <NA>, 1, 2, <NA>, 1, 2, <NA>]\n"
104104
"Length: 3000, dtype: Int64"
105105
)
106106
result = repr(data)
@@ -673,7 +673,7 @@ def test_to_numpy_na_raises(self, dtype):
673673

674674
def test_astype_str(self):
675675
a = pd.array([1, 2, None], dtype="Int64")
676-
expected = np.array(["1", "2", "NA"], dtype=object)
676+
expected = np.array(["1", "2", "<NA>"], dtype=object)
677677

678678
tm.assert_numpy_array_equal(a.astype(str), expected)
679679
tm.assert_numpy_array_equal(a.astype("str"), expected)
@@ -683,7 +683,7 @@ def test_frame_repr(data_missing):
683683

684684
df = pd.DataFrame({"A": data_missing})
685685
result = repr(df)
686-
expected = " A\n0 NA\n1 1"
686+
expected = " A\n0 <NA>\n1 1"
687687
assert result == expected
688688

689689

0 commit comments

Comments
 (0)