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
issue with types for pandas.DataFrame.from_dict method:
dtype is restricted to str in the stub file when pands allows for str, type and None
columns is restricted to list of strings when pandas allows for much more (at least: str, int, float, datetime)
To Reproduce
minimal exemple:
importpandasaspdimportdatetimedata= {'l1': [1, 2, 3],
'l2': [4, 5, 6]}
# all of the following are accepted by pandas# however mypy complains with the last 3pd.DataFrame.from_dict(data, orient='index') # OKpd.DataFrame.from_dict(data, orient='index', dtype='float') # OKpd.DataFrame.from_dict(data, orient='index', columns=['a', 'b', 'c']) # OKpd.DataFrame.from_dict(data, orient='index', dtype=float) # NOKpd.DataFrame.from_dict(data, orient='index', dtype=None) # NOKpd.DataFrame.from_dict(data, orient='index',
columns=[1.0, 2, datetime.datetime.now()]) # NOK
type checker : mypy
typing errors:
from_dict_test.py:12: error: Argument "dtype" to "from_dict" of "DataFrame" has incompatible type "type[float]"; expected "str" [arg-type]
from_dict_test.py:13: error: Argument "dtype" to "from_dict" of "DataFrame" has incompatible type "None"; expected "str" [arg-type]
from_dict_test.py:15: error: List item 0 has incompatible type "float"; expected "str" [list-item]
from_dict_test.py:15: error: List item 1 has incompatible type "int"; expected "str" [list-item]
from_dict_test.py:15: error: List item 2 has incompatible type "datetime"; expected "str" [list-item]
Please complete the following information:
OS: Windows
Windows 10 22H2 build: 19045.4170
Python 3.12.2 | packaged by Anaconda, Inc. | (main, Feb 27 2024, 17:28:07) [MSC v.1916 64 bit (AMD64)] on win32
mypy 1.9.0
pandas-stubs 2.2.0.240218
The text was updated successfully, but these errors were encountered:
* tentative solution for #896
* remove Unnecessary "# pyright: ignore" rule error
* improving dataframe.from_dict test
* check(assert_type every test
* remove unwanted ellipsis
* Adding overload and test to cover when litteral is not used
* Revert "Adding overload and test to cover when litteral is not used"
This reverts commit f760452.
---------
Co-authored-by: Laurent Mutricy <[email protected]>
Describe the bug
issue with types for
pandas.DataFrame.from_dict
method:dtype
is restricted to str in the stub file when pands allows forstr
,type
andNone
columns
is restricted to list of strings when pandas allows for much more (at least: str, int, float, datetime)To Reproduce
mypy
Please complete the following information:
The text was updated successfully, but these errors were encountered: