Skip to content

API: set should not be considered list_like #23061

Closed
@h-vetinari

Description

@h-vetinari

The name of the function is_list_like from pandas.core.dtypes.common suggests that whatever gets True returned will be "like a list". As such, it's used in a handful of places - e.g. I got asked to use it in #20347, and now again in #22486. What I found out in the latter one is that it's true for sets:

>>> from pandas.core.dtypes.common import is_list_like
>>> is_list_like({1, 2, 3})
True

This has some uncomfortable consequences - for str.cat it's a bug (#23009), and for df.set_index it would be too.

@jreback asked me to try out removing set from is_list_like (#22486 (comment)), so this issue is following up on that.

@h-vetinari why don't you try (separate PR) excluding set from is_list_like and see what the implications of that are.

There are some rare cases like .isin, where sets should also be included. I'd say to have a looser definition is_set_like that's basically is_list_like or set. Alternatively, one could think of is_list_like(strict=False) to include sets.

Another question is if this needs a deprecation cycle and how?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions