Skip to content

Commit

Permalink
Update NA repr
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Jan 8, 2020
1 parent 4a039c6 commit 12aa3d3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
5 changes: 1 addition & 4 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ class NAType(C_NAType):
return NAType._instance

def __repr__(self) -> str:
return "NA"

def __str__(self) -> str:
return "NA"
return "<NA>"

def __bool__(self):
raise TypeError("boolean value of NA is ambiguous")
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ def _format(x):
if x is None:
return "None"
elif x is NA:
return "NA"
return formatter(x)
elif x is NaT or np.isnat(x):
return "NaT"
except (TypeError, ValueError):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_astype():
tm.assert_numpy_array_equal(result, expected)

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

# no missing values
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/arrays/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ def test_repr_dtype(dtype, expected):

def test_repr_array():
result = repr(integer_array([1, None, 3]))
expected = "<IntegerArray>\n[1, NA, 3]\nLength: 3, dtype: Int64"
expected = "<IntegerArray>\n[1, <NA>, 3]\nLength: 3, dtype: Int64"
assert result == expected


def test_repr_array_long():
data = integer_array([1, 2, None] * 1000)
expected = (
"<IntegerArray>\n"
"[ 1, 2, NA, 1, 2, NA, 1, 2, NA, 1,\n"
"[ 1, 2, <NA>, 1, 2, <NA>, 1, 2, <NA>, 1,\n"
" ...\n"
" NA, 1, 2, NA, 1, 2, NA, 1, 2, NA]\n"
" <NA>, 1, 2, <NA>, 1, 2, <NA>, 1, 2, <NA>]\n"
"Length: 3000, dtype: Int64"
)
result = repr(data)
Expand Down Expand Up @@ -673,7 +673,7 @@ def test_to_numpy_na_raises(self, dtype):

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

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

df = pd.DataFrame({"A": data_missing})
result = repr(df)
expected = " A\n0 NA\n1 1"
expected = " A\n0 <NA>\n1 1"
assert result == expected


Expand Down

0 comments on commit 12aa3d3

Please sign in to comment.