ENH: Hand numpy-like arrays with is_list_like
State: closed

- [ ] follows #39852 
- [x] tests added / passed
- [ ] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#code-standards) for how to run them
- [ ] whatsnew entry


Labels:
name: Stale

Comments:
@jreback let's try this again. This time just updating the single `is_list_like`. Such a change allows Pint EA to pass many more tests, as is shown by the removal of `@pytest.mark.xfail(run=True, reason="__iter__ / __len__ issue")` in multiple places in https://github.com/hgrecco/pint-pandas/pull/59/files.

Fixes to `is_scalar` will also have to follow but leaving that for a separate PR is probably simplest. 

How can I tell how big the performance hit is?
> How can I tell how big the performance hit is?

for something like this usually do `%timeit is_list_like(foo)` with a few different types of inputs, and report the results on both master and the PR
Ok

```python
In [1]: import pandas as pd                                                                                                                                                     

In [2]: import numpy as np                                                                                                                                                      

In [3]: a1 = [1, 2, 3] 
   ...: a2 = np.array([1, 2, 3]) 
   ...: a3 = np.array([1, 2, 3])[0]                                                                                                                                             

In [4]: %timeit pd.api.types.is_list_like(a1)                                                                                                                                   
412 ns ± 22 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # master
624 ns ± 15.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # pr

In [5]: %timeit pd.api.types.is_list_like(a2)                                                                                                                                   
415 ns ± 20.4 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # master
416 ns ± 13.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # pr

In [6]: %timeit pd.api.types.is_list_like(a3)                                                                                                                                   
485 ns ± 140 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # master
446 ns ± 120 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # pr
```

Almost identical results to https://github.com/pandas-dev/pandas/pull/35127#issuecomment-654069720.

Using `np.iterable` gives a third option where things are faster for lists and arrays but slower for scalars (see https://github.com/pandas-dev/pandas/pull/35127#issuecomment-654530394).

If we end up back at this comment https://github.com/pandas-dev/pandas/pull/35127#issuecomment-653954875 then we are simply going in circles between that comment and this comment https://github.com/pandas-dev/pandas/pull/35127#issuecomment-777155765
FYI https://github.com/pandas-dev/pandas/pull/39852 which changes the bogey. Not sure if the c-function is better or worse for you.
> Not sure if the c-function is better or worse for you.

Thanks, that helps for sure (list slightly slower but might also be because I'm running lots of stuff at the moment...). I think we can include this without performance hits after #39852 then.
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
@znicholls Thanks for the PR. closing as stale. ping if you want to continue.