Skip to content

DOC: Update warning in Index.values docstring to clarify index modification which causes segmentation fault #61069

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

Merged
merged 5 commits into from
Mar 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4912,6 +4912,10 @@ def values(self) -> ArrayLike:
:meth:`Index.to_numpy`, depending on whether you need
a reference to the underlying data or a NumPy array.

Modifying 'Index.values' directly is not supported and can lead to memory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, could you add a .. versionchanged:: 3.0.0 tag mentioning that the result is read-only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroeschke thank you for the updates.

please confirm if the below statement should be replaced with the existing one or to modify the first line.

.. versionchanged:: 3.0.0
The result is now read-only, preventing memory corruption or segmentation
faults that could occur when attempting to modify it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just

.. versionchanged:: 3.0.0
    The returned array is read-only.

corruption or segmentation faults. This is because 'Index.values' provides
a direct reference to internal NumPy data.

Returns
-------
array: numpy.ndarray or ExtensionArray
Expand Down
Loading