Open toobaz opened 5 years ago
By the way: clearly documenting, once and for all, what a "list-like" is in pandas is an essential part of the fix.
Can I work on documentation part , or its totally internal ?
Loosely related xref: #24688
It's maybe worth noting that my original plan for #23065 was to introduce a strict
kwarg for is_list_like
, but that was voted down in favor of a more specific keyword (see e.g. here).
It may be worth revisiting that decision if people want to resolve the issue brought up in the OP. The question "what is list-like" could then have several answers (which may or may not be desirable). Examples:
is_list_like(obj, allow_sets=True, allow_tuples=True, allow_...)
is_list_like(obj, strict=False)
Tagging participants of the discussion in #23065: @TomAugspurger @jorisvandenbossche @jschendel @jreback
Code Sample, a copy-pastable example if possible
Problem description
We discussed several times the fact that tuples in pandas should not be considered collections of things, but rather
MultiIndex
keys, orDataFrame
(simple way to discriminate: if you could easily add an element, it is a collection; if instead the number of elements is somewhat hardcoded, it is not).
It is perfectly natural, and would solve problems/hacks such as
https://github.com/pandas-dev/pandas/commit/32ee9732b823448b87848f6bcaefdc762868999c#diff-1e79abbbdd150d4771b91ea60a4e1cc7R2701
https://github.com/pandas-dev/pandas/pull/24697#issuecomment-453078627
... and many others, to change the behavior of
is_list_like
, which is used in many places.See #23061 for a similar fix (although the similarity breaks whereas
set
s are intrinsically different from alist
, while fortuple
s it is a design decision).I do expect some tests to break, and I also expect that in some cases, we'll want to preserve backwards compatibility... but at least let's set a sane default.
Expected Output
False
Output of
pd.show_versions()