Skip to content
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

mypy issue when value of the dict passed to from_dict() are scalars #152

Closed
johanvergeer opened this issue Mar 16, 2022 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@johanvergeer
Copy link
Contributor

When a scalar value is used in the dict that is passed to from_dict(), then mypy will raise an error, while Pandas can handle this input just fine.

>>> import pandas as pd
>>> data = {"a": 1, "b": 2}
>>> dataframe = pd.DataFrame.from_dict(data, orient="index", columns=["foo"])
>>> dataframe
   foo
a    1
b    2

Would it be better to change the stubs for from_dict() to also allow scalars?

I did have a look at the pandas._typing module, which contains some definitions for scalars, but that doesn't seem to include numpy types.

PythonScalar = Union[str, int, float, bool]
PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
Scalar = Union[PythonScalar, PandasScalar]
@zkrolikowski-vl zkrolikowski-vl self-assigned this Mar 17, 2022
@zkrolikowski-vl zkrolikowski-vl added the bug Something isn't working label Mar 17, 2022
@zkrolikowski-vl
Copy link
Collaborator

zkrolikowski-vl commented Jul 1, 2022

pandas-stubs has moved to a new repository and will now be managed alongside pandas itself: https://github.com/pandas-dev/pandas-stubs

You might try using the newest version pip install pandas-stubs==1.4.2.220626 which comes from that repository. If it doesn't work please considering opening an issue in the new repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants