BUG: Fix pd.NA `na_rep` truncated in to_csv
State: closed

- [x] closes #29975
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Missing-data
description: np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
name: Output-Formatting
description: __repr__ of pandas objects, to_string

Comments:
Hello @jbman223! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2020-01-01 17:41:44 UTC
Revert the change in internals, and skip or xfail the test. There are
probably other examples in that file for how to do it.

On Tue, Dec 10, 2019 at 1:59 PM Jacob Buckheit <notifications@github.com>
wrote:

> *@jbman223* commented on this pull request.
> ------------------------------
>
> In pandas/core/internals/blocks.py
> <https://github.com/pandas-dev/pandas/pull/30146#discussion_r356248230>:
>
> > @@ -657,8 +657,11 @@ def to_native_types(self, slicer=None, na_rep="nan", quoting=None, **kwargs):
>          mask = isna(values)
>
>          if not self.is_object and not quoting:
> -            itemsize = writers.word_len(na_rep)
> -            values = values.astype("<U{size}".format(size=itemsize))
> +            try:
> +                itemsize = writers.word_len(na_rep)
> +                values = values.astype("<U{size}".format(size=itemsize))
>
> So @TomAugspurger <https://github.com/TomAugspurger>, just to clarify,
> you think it would be better for me to revert the code change in
> pandas/core/internals/blocks.py and remove the failing test?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/30146?email_source=notifications&email_token=AAKAOITDH4PFBC4EWYUK7QDQX7YK3A5CNFSM4JYAUKPKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCOWQQDQ#discussion_r356248230>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAKAOITAFEAHCRXM5PSCJTLQX7YK3ANCNFSM4JYAUKPA>
> .
>

> Revert the change in internals, and skip or xfail the test. There are probably other examples in that file for how to do it.
> […](#)
> On Tue, Dec 10, 2019 at 1:59 PM Jacob Buckheit ***@***.***> wrote: ***@***.**** commented on this pull request. ------------------------------ In pandas/core/internals/blocks.py <[#30146 (comment)](https://github.com/pandas-dev/pandas/pull/30146#discussion_r356248230)>: > @@ -657,8 +657,11 @@ def to_native_types(self, slicer=None, na_rep="nan", quoting=None, **kwargs): mask = isna(values) if not self.is_object and not quoting: - itemsize = writers.word_len(na_rep) - values = values.astype("<U{size}".format(size=itemsize)) + try: + itemsize = writers.word_len(na_rep) + values = values.astype("<U{size}".format(size=itemsize)) So @TomAugspurger <https://github.com/TomAugspurger>, just to clarify, you think it would be better for me to revert the code change in pandas/core/internals/blocks.py and remove the failing test? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#30146?email_source=notifications&email_token=AAKAOITDH4PFBC4EWYUK7QDQX7YK3A5CNFSM4JYAUKPKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCOWQQDQ#discussion_r356248230>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAKAOITAFEAHCRXM5PSCJTLQX7YK3ANCNFSM4JYAUKPA> .

what would you recommend as a failure reason for the skip or xfails?
can you merge master and will look again
thanks @jbman223