Skip to content

Commit 6f7f367

Browse files
TomAugspurgerjorisvandenbossche
authored andcommitted
BUG: Series[EA].astype(str) works (#20581)
Closes #20578
1 parent 5edc5c4 commit 6f7f367

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
655655

656656
# astype formatting
657657
else:
658-
values = self.values
658+
values = self.get_values()
659659

660660
else:
661661
values = self.get_values(dtype=dtype)

pandas/tests/extension/base/casting.py

+5
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ def test_tolist(self, data):
1616
result = pd.Series(data).tolist()
1717
expected = list(data)
1818
assert result == expected
19+
20+
def test_astype_str(self, data):
21+
result = pd.Series(data[:5]).astype(str)
22+
expected = pd.Series(data[:5].astype(str))
23+
self.assert_series_equal(result, expected)

pandas/tests/extension/json/test_json.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ def test_sort_values_missing(self, data_missing_for_sorting, ascending):
127127

128128

129129
class TestCasting(base.BaseCastingTests):
130-
pass
130+
@pytest.mark.xfail
131+
def test_astype_str(self):
132+
"""This currently fails in NumPy on np.array(self, dtype=str) with
133+
134+
*** ValueError: setting an array element with a sequence
135+
"""
131136

132137

133138
class TestGroupby(base.BaseGroupbyTests):

0 commit comments

Comments
 (0)