-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Python 3.14 may not increment refcount #61368
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
Thanks for the report! It sounds like we may need to disable these warnings for Python 3.14+ if the refcount cannot be relied upon. |
Since CoW is implemented using refcount, could there also be cases where we believe data is not being shared but it really is? |
The actual Copy-on-Write mechanism itself is implement using weakrefs, and does not rely on refcounting, I think. The refcounts are used for the warning about chained assignments. While not essential for ensure correct behaviour (correctly copying when needed), those warnings are quite important towards the users for migrating / generally avoiding mistakes in the future (giving how widely spread chained assignment is). So ideally we would be able to keep this warning working.
Do you know if there is a technical explanation of this somewhere? (or the PR implementing it? Didn't directly find anything mentioned in the 3.14 whatsnew page) |
Hi! Sorry for the random comment, but @ngoldbaum pointed out this issue to me. I'm the author of the optimization. Happy to answer any questions or help brainstorm a solution with you. |
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
Issue Description
With python 3.14 and the Pandas main branch (or 2.2.3 with
pd.options.mode.copy_on_write = "warn"
) the above fails with:With Python 3.14 there will be an optimization where the reference count is not incremented if Python can be sure that something above the calling scope will hold a reference for the life time of a scope. This is causing a number of failures in test suites when reference counts are checked. In this case I think it erroneously triggering the logic that the object is a intermediary.
Found this because it is failing the mpl test suite (this snippet is extracted from one of our tests).
With py313 I do not get this failure.
Expected Behavior
no warning
Installed Versions
It is mostly development versions of things, this same env with pd main also fails.
INSTALLED VERSIONS
commit : 0691c5c
python : 3.14.0a7+
python-bits : 64
OS : Linux
OS-release : 6.14.2-arch1-1
Version : #1 SMP PREEMPT_DYNAMIC Thu, 10 Apr 2025 18:43:59 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.3
numpy : 2.3.0.dev0+git20250427.4961a14
pytz : 2025.2
dateutil : 2.9.0.post1.dev6+g35ed87a.d20250427
pip : 25.0.dev0
Cython : 3.1.0b1
sphinx : None
IPython : 9.3.0.dev
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.4
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.3.2
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 6.0.0.alpha0
matplotlib : 3.11.0.dev732+g8fedcea7fc
numba : None
numexpr : 2.10.3.dev0
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.0.dev32+g7ef189757
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.16.0.dev0+git20250427.55cae81
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : 2025.3.1
xlrd : 2.0.1
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: