ENH: Change implementation of pandas.api.types.is_list_like to check for iterability in more pythonic way #43196
Labels
API Design
Closing Candidate
May be closeable, needs more eyeballs
Enhancement
Needs Discussion
Requires discussion from core team before further action
Is your feature request related to a problem?
Yes, this would improve predictability of behavior with pandas extension arrays.
Describe the solution you'd like
pandas.api.types.is_list_like
can check for iterability in a more pythonic way according to https://docs.python.org/3/glossary.html#term-iterable. This would result in the appropriate call beingiter(obj)
rather than checking for__iter__
attribute.API breaking implications
This will not affect the API.
Describe alternatives you've considered
Alternative solutions include communicating to third parties that they must change their extension arrays to include
hasattr(q, "__iter__") == False
to make sure that classes with ambiguous data iterability (may contain either scalar or array-like data) are perceived as utterable when they contain scalar data.Additional context
Opened a bug report for this issue. I think an enhancement request is more appropriate, but I am linking the previous (closed) bug report as it includes useful information.
#43195
The text was updated successfully, but these errors were encountered: