ENH: Allow export of mixed columns to Stata strl
State: closed

Enable export of large columns to Stata strls when the column
contains None as a null value

closes #23633

- [x] closes #23633
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Enhancement
name: IO Stata
description: read_stata, to_stata

Comments:
Hello @bashtage! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/io/stata.py`](https://github.com/bashtage/pandas/blob/75f9d808f569bd4fcfa38c2b4a1988cc269e626d/pandas/io/stata.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_stata.py`](https://github.com/bashtage/pandas/blob/75f9d808f569bd4fcfa38c2b4a1988cc269e626d/pandas/tests/io/test_stata.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23692?src=pr&el=h1) Report
> Merging [#23692](https://codecov.io/gh/pandas-dev/pandas/pull/23692?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a197837c4067469478b13e491a21b58cb78ed165?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/23692/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23692?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #23692   +/-   ##
=======================================
  Coverage   92.24%   92.24%           
=======================================
  Files         161      161           
  Lines       51318    51318           
=======================================
  Hits        47339    47339           
  Misses       3979     3979
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.63% <ø> (ø)` | :arrow_up: |
| #single | `42.31% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23692?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23692?src=pr&el=footer). Last update [a197837...75f9d80](https://codecov.io/gh/pandas-dev/pandas/pull/23692?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

does this break idempotency?  (i think answer is no, this is round-trippable)
I think yes because Stata doesn't have a string missing value. When the Stata file is read back in to Pandas, the `None` values are `''`.

This already happens with shorter strings with the Stata 114 writer. This PR allows the same to happen with strings longer than 245 characters in the 117 writer.

```py
>>> import pandas as pd
>>> df = pd.DataFrame({'a': ['abc', None]})
>>> df.to_stata('test.dta')
>>> pd.read_stata('test.dta')
```
```
Out[7]:
   index    a
0      0  abc
1      1
```
> does this break idempotency? (i think the answer is no, this is round-trippable)

Yes. Essentially you get None->'' conversion in mixed columns since there is no missing value for strings in Stata.

The only way to have idempotency would be to raise on mixed string columns so that None is not allowed in string columns. Then users would need to convert None to '' before saving, so that '' -> file -> ''.
thanks @bashtage