Skip to content

Commit 45f7a45

Browse files
committed
Fix failing test
1 parent a1d4509 commit 45f7a45

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ You can use the alias ``"string"`` as well.
8686
s
8787
8888
The usual string accessor methods work. Where appropriate, the return type
89-
of the Series or columns of a DataFrame will also have string dtype.
89+
of the Series or columns of a DataFrame will also have string dtype. (:issue:`29975`)
9090

9191
.. ipython:: python
9292
@@ -853,7 +853,6 @@ Other
853853
- Fix :class:`AbstractHolidayCalendar` to return correct results for
854854
years after 2030 (now goes up to 2200) (:issue:`27790`)
855855
- Bug in :meth:`Series.count` raises if use_inf_as_na is enabled (:issue:`29478`)
856-
- Bug in :meth:`DaataFrame.to_csv` when supplied a series with a ``dtype="string"`` and a ``na_rep``, the ``na_rep`` was being truncated to 2 characters. (:issue:`29975`)
857856

858857
.. _whatsnew_1000.contributors:
859858

pandas/core/internals/blocks.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,11 @@ def to_native_types(self, slicer=None, na_rep="nan", quoting=None, **kwargs):
657657
mask = isna(values)
658658

659659
if not self.is_object and not quoting:
660-
itemsize = writers.word_len(na_rep)
661-
values = values.astype("<U{size}".format(size=itemsize))
660+
try:
661+
itemsize = writers.word_len(na_rep)
662+
values = values.astype("<U{size}".format(size=itemsize))
663+
except:
664+
values = np.array(values, dtype="object")
662665
else:
663666
values = np.array(values, dtype="object")
664667

@@ -1775,10 +1778,10 @@ def to_native_types(self, slicer=None, na_rep="nan", quoting=None, **kwargs):
17751778

17761779
try:
17771780
values[mask] = na_rep
1778-
values = values.astype(str)
17791781
except Exception:
17801782
# eg SparseArray does not support setitem, needs to be converted to ndarray
17811783
return super().to_native_types(slicer, na_rep, quoting, **kwargs)
1784+
values = values.astype(str)
17821785

17831786
# we are expected to return a 2-d ndarray
17841787
return values.reshape(1, len(values))

0 commit comments

Comments
 (0)