-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Should DataFrame constructor allow sets for index and columns? #47215
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
Comments
no sets are unordered but definition we shouldn't allow this (it's possible we convert these though) |
I don't think we should view (1) as an API change, assuming there is no indication in the documentation that sets are allowed. The API is what is documented as being supported, not whether or not it works by chance. +1 on not allowing sets. |
we are not that clear on our type definitions for the parameters section of the docstrings the only mention of array-like in https://pandas.pydata.org/pandas-docs/stable/development/contributing_docstring.html#pandas-docstring-guide
Now, if a If compatible means that can be converted to a numpy array then So for all intents and purposes, However, I think we still sometimes deprecate things that happen to work by chance first to err on the side of caution. For the stubs, disallowing sets is fine and the right thing to do. +1 for deprecating not allowing sets. |
I belive this change is why I'm getting type checking warnings for using a |
Are you using |
While looking into some typing issues, I found that the following code works:
The result:
We document that the
columns
andindex
arguments should beIndex
or "array-like". Certainly aset
is not array-like!Internally, we type those arguments as
Axes
, which is defined asCollection[Any]
, but in the pandas-stubs, we are more restrictive, not allowing sets to be passed.I think we should disallow
set
as a type in the constructor, since it doesn't follow the documentation, and if you were to use it, the behavior is unclear. We could do one or more of the following:DataFrame
constructor to raise an error ifindex
orcolumns
are setsAxes
to be more restrictive, i.e., not useCollection
I think we should definitely do (2), but I'm not sure if (1) would be considered a change in the API, since we never documented that sets are acceptable, but they did work (and possibly give funky behavior).
The text was updated successfully, but these errors were encountered: