You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When you do DataFrame.to_dict(orient="index"), and you are using default integer index and string columns, you will get a Dict[int, Dict[str, Any]] at runtime. The current annotations do not reflect this nested dictionary, they instead return a Dict[Hashable, Any]. I understand that the exact type this returns has changed slightly after recent commits by @twoertwein, but the issue still stands.
This issue could be broadened to more precisely annotate all possible values of orient if desired. For instance, orient="split" probably should return a TypedDict that has index and columns as keys.
To Reproduce
Any usage of to_dict(orient="index") should reproduce this. Below is a screenshot of an example:
The text was updated successfully, but these errors were encountered:
The current annotations do not reflect this nested dictionary, they instead return a Dict[Hashable, Any]. I understand that the exact type this returns has changed slightly after recent commits by @twoertwein, but the issue still stands.
MutableMapping[Hashable, Any] (the current return annotation) should be compatible with MutableMapping[Hashable, MutableMapping[Hashable, Any]] except that you don't get type checking for the Any part.
DataFrame is not generic in the index and columns, so the best we could do is what you suggested MutableMapping[Hashable, MutableMapping[Hashable, Any]]. Feel free to open a PR (including tests) but let's first wait for what @Dr-Irv thinks about that.
DataFrame is not generic in the index and columns, so the best we could do is what you suggested MutableMapping[Hashable, MutableMapping[Hashable, Any]]. Feel free to open a PR (including tests) but let's first wait for what @Dr-Irv thinks about that.
I'm fine with expanding the overloads on to_dict() to handle the different cases of the orient value. There will be a bunch of new overloads, but we can also be incremental about it.
Agree that the best we can do is MutableMapping[Hashable, MutableMapping[Hashable, Any]], but also have to take into account the value of the into argument.
Describe the bug
When you do
DataFrame.to_dict(orient="index")
, and you are using default integer index and string columns, you will get aDict[int, Dict[str, Any]]
at runtime. The current annotations do not reflect this nested dictionary, they instead return aDict[Hashable, Any]
. I understand that the exact type this returns has changed slightly after recent commits by @twoertwein, but the issue still stands.Expectation: returns
MutableMapping[Hashable, MutableMapping[Hashable, Any]]
This issue could be broadened to more precisely annotate all possible values of
orient
if desired. For instance,orient="split"
probably should return aTypedDict
that hasindex
andcolumns
as keys.To Reproduce
Any usage of
to_dict(orient="index")
should reproduce this. Below is a screenshot of an example:The text was updated successfully, but these errors were encountered: