ENH: Improve error message for empty object array
State: closed

Improve the error message shown when an object array is empty

closes #23572

- [x] closes #23572
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


No what's new since too small a change and no test needed.

Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas
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/3eb95fd30d00ce69526a7a422a939d8a3b6772e4/pandas/io/stata.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23718?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@a23f901`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff            @@
##             master   #23718   +/-   ##
=========================================
  Coverage          ?   92.25%           
=========================================
  Files             ?      161           
  Lines             ?    51384           
  Branches          ?        0           
=========================================
  Hits              ?    47405           
  Misses            ?     3979           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.64% <ø> (?)` | |
| #single | `42.32% <ø> (?)` | |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23718?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/23718?src=pr&el=footer). Last update [a23f901...527a1e3](https://codecov.io/gh/pandas-dev/pandas/pull/23718?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

I also extended the test in my previous PR to ensure that the case with all `None` when specifically requested to write as a strl passes.  I hope this is OK, but could move to a new PR is needed.
@bashtage Consider adding the offending column to the error like in #23646. The all `None` case isn't hard to handle, but most of the work for me is identifying the column(s) that are the problem in datasets with hundreds of columns.

Since it's throwing on a particular column, it may be that the first encountered column is the only one that can be named, but that's still helpful. An alternative would be providing a brief code example that will identify these all `None` columns (and perhaps an example of fixing it with `convert_strl`).

I could imagine relatively novice pandas users (i.e. Stata switchers) hitting this error, so I'd lean toward a little more hand-holding/direction. Happy to hear counterarguments, though.
@jtkiley I added this.
@bashtage Thanks for this (looks great) and all you do on the Stata format. It's a big help for those of us working with both, and it helps smooth the work I do to train Stata users to use pandas.
thanks @bashtage