-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: set should not be considered list_like #23061
Comments
FWIW, changing these |
I imagine this issue extends beyond just In [2]: d = dict(zip('xyz', [10, 20, 30]))
In [3]: d
Out[3]: {'x': 10, 'y': 20, 'z': 30}
In [4]: is_list_like(d)
Out[4]: True
In [5]: s = pd.Series(list('abc'))
In [6]: s.str.cat(d)
Out[6]:
0 ax
1 by
2 cz
dtype: object Quickly reading over the associated issues, it looks like what you want is to basically place an additional restriction on |
|
Added a first draft of a PR in #23065. Happy to add |
I don't think that's a good idea. In the past changing these have led to surprising breaks in user code. These checks are used all over pandas, so it's hard to predict the ramifications of changing one. If a user has a set-like object, then what would they do when they see that warning cropping up from their object? I think if the caller needs to know that the collection is ordered, then they should assert that independently. |
They're not gonna see it from pandas, unless they |
The name of the function
is_list_like
frompandas.core.dtypes.common
suggests that whatever getsTrue
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:This has some uncomfortable consequences - for
str.cat
it's a bug (#23009), and fordf.set_index
it would be too.@jreback asked me to try out removing
set
fromis_list_like
(#22486 (comment)), so this issue is following up on that.There are some rare cases like
.isin
, where sets should also be included. I'd say to have a looser definitionis_set_like
that's basicallyis_list_like or set
. Alternatively, one could think ofis_list_like(strict=False)
to include sets.Another question is if this needs a deprecation cycle and how?
The text was updated successfully, but these errors were encountered: