BUG: warning from typing library if you subclass a DataFrame using Generic with python 3.11 · Issue #49649 · pandas-dev/pandas (original) (raw)
Pandas version checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd from typing import TypeVar, Generic
T = TypeVar("T")
class MyDataFrame(pd.DataFrame, Generic[T]): ...
def func() -> MyDataFrame[int]: return MyDataFrame[int]({"foo": [1, 2, 3]})
x = func() print(x)
Issue Description
With pandas 1.5.1 and python 3.10, the code above gives no warning at runtime.
With pandas 1.5.1 and python 3.11, you get a warning from the typing library at runtime:
C:\Anaconda3\envs\pandasstubs311\Lib\typing.py:1253: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
result.__orig_class__ = self
We have testing code in pandas-stubs that uses this, because it was reported by the people developing the pandera
library.
Expected Behavior
No warning.
We're doing something in pandas that doesn't allow a Generic
subclass to be created with python 3.11.
Installed Versions
INSTALLED VERSIONS
commit : 91111fd
python : 3.11.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19043
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.1
pip : 22.3.1
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : 1.0.10
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : 1.4.43
tables : None
tabulate : 0.9.0
xarray : 2022.11.0
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None