-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
BUG: Segmentation Fault when changing a column name in a DataFrame #60954
Comments
This is definitely not supported; you're modifying the internal numpy data inside the In the meantime, the supported way to do what you are trying to do in your example would be |
The segmentation fault mainly due to the memory corruption since it is not recommended with the current version. Although if you try to pandas 2 enables copy-on-write might throw proper error instead of corrupting memory. So instead of modifying the |
Thanks for the report. Agreed this is not supported, but I think that should be spelled out more clearly in the docstring of |
Thanks for the reply @Manju080. A bit more detail beyond the example. So this solution, or even the canonical one But there is one situation where this would be insufficient: if two columns have the same exact name (which from my knowledge of Pandas is perfectly valid). Now imagine you would want to change only one of the column's name. This leads to one situation where the change inplace of the column name, through its ordinal index, would allow the clear identification of the column to be changed. Without this, the only safe solution is to deep copy all column names into a list, apply the change and and make the bulk replace |
Yes, that seems like it. Note that I raised this issue not exactly to find a solution (I had one, do a bulk replace of the column names and now I also have yours) but to highlight that this leads to a bug really hard to diagnose, as there is no warning whatsoever or blocking of any sorts. As a user I would expect somehow for this operation to be blocked and that a traceback is raised. As I had wrote:
|
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
When a column name from a DataFrame is changed inplace (at the values), sometimes it leads to a segmentation fault. This seems more likely if the DataFrame contains mixed element types (as per example below).
Hypotheses are:
Example:
Expected Behavior
Though the operation may be debatable (the change inplace of the column name via
df.column.values[i] = new_name
), it is a valid operation without any other warning or error message. The ensuing segmentation fault is completely random (so very hard to diagnose).Hence the expected behaviour is to either block these operations, or alternatively to fully allow those if these are to be permitted.
Installed Versions
pandas : 2.2.3
numpy : 2.0.2
pytz : 2025.1
dateutil : 2.9.0.post0
pip : 24.0
Cython : None
sphinx : None
IPython : 8.18.1
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.4
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : None
xarray : 2024.7.0
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: