-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
API: Copy inputs in Index subclass constructors by default (GH#63388) #63398
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
mroeschke
merged 31 commits into
pandas-dev:main
from
zacharym-collins:api-copy-index-subclasses
Dec 18, 2025
Merged
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
0537d03
TST: add regression tests for GH#63388 (DatetimeIndex copy behavior)
zacharym-collins 3b7b85b
ENH: Copy inputs in DatetimeIndex constructor by default (GH#63388)
zacharym-collins 67eaf05
CLN: change test name to include datetimeindex for clarity
zacharym-collins f59ab9e
TST: Add regression tests for GH#63388 (TimedeltaIndex copy behavior)
zacharym-collins 9221e5a
ENH: Copy inputs in TimedeltaIndex constructor by default (GH#63388)
zacharym-collins 32ee4dc
TST: correct test to use array instead of np.array
zacharym-collins b55f4a0
TST: correct test to use array instead of np.array
zacharym-collins 91e78da
TST: Add regression tests for GH#63388 (PeriodIndex copy behavior)
zacharym-collins 1252782
ENH: Copy inputs in PeriodIndex constructor by default (GH#63388)
zacharym-collins 923c949
TST: Add regression tests for GH#63388 (IntervalIndex copy behavior)
zacharym-collins 122f554
ENH: Copy inputs in IntervalIndex constructor by default (GH#63388)
zacharym-collins 66a37fe
STYLE: Apply isort fixes
zacharym-collins 5a211cc
DOC: Add release note for GH#63388
zacharym-collins 9373333
TYP: Fix mypy errors with type ignores
zacharym-collins bc3c54a
TYP: Fix mypy errors using bool(copy) and ignores
zacharym-collins 6731252
STY: Apply pre-commit fixes
zacharym-collins 9acc8d1
FIX: Update regression test for copy default
zacharym-collins 180fa7e
FIX: handle string dtypes
zacharym-collins f7a00a4
FIX: Update test_array_tz to use copy=False
zacharym-collins ca90c29
STY: apply pre-commit fixes
zacharym-collins 75a3aac
CLN: Remove unused type ignores
zacharym-collins e689f7b
REF: Add Index._maybe_copy_input helper (GH#63388)
zacharym-collins 65d8012
REF: Use _maybe_copy_input in Index subclasses (GH#63388)
zacharym-collins 05d4924
DOC: Update release note for GH#63388
zacharym-collins 1e61eb6
REF: Rename copy helper to _maybe_copy_array_input and add type hints…
zacharym-collins 5e87eab
REF: update to use renamed _maybe_copy_array_input classmethod (GH#63…
zacharym-collins c290a30
REF: Return strict bool from copy helper and clean up call sites (GH#…
zacharym-collins 02af4fb
STY: Revert import formatting (GH#63388)
zacharym-collins fd6de1d
Merge remote-tracking branch 'upstream/main' into api-copy-index-subc…
zacharym-collins e2b0f49
REF: Use copy helper for GH#63306 logic in Index constructor
zacharym-collins f8721aa
STY: Apply ruff formatting to method signature
zacharym-collins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import numpy as np | ||
|
|
||
| from pandas import ( | ||
| Interval, | ||
| IntervalIndex, | ||
| Series, | ||
| array, | ||
| ) | ||
| import pandas._testing as tm | ||
| from pandas.tests.copy_view.util import get_array | ||
|
|
||
|
|
||
| def test_constructor_copy_input_interval_ea_default(): | ||
| # GH 63388 | ||
| arr = array([Interval(0, 1), Interval(1, 2)]) | ||
| idx = IntervalIndex(arr) | ||
| assert not tm.shares_memory(arr, idx.array) | ||
|
|
||
|
|
||
| def test_series_from_temporary_intervalindex_readonly_data(): | ||
| # GH 63388 | ||
| arr = array([Interval(0, 1), Interval(1, 2)]) | ||
| arr._left.flags.writeable = False | ||
| arr._right.flags.writeable = False | ||
| ser = Series(IntervalIndex(arr)) | ||
| assert not np.shares_memory(arr._left, get_array(ser)._left) | ||
| ser.iloc[0] = Interval(5, 6) | ||
| expected = Series([Interval(5, 6), Interval(1, 2)], dtype="interval[int64, right]") | ||
| tm.assert_series_equal(ser, expected) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove this note (I'll probably be adding something related to this in the copy on write guide)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is probably still worth mentioning it here explicitly as well? But I think we can simplify this to just say that all the Index constructors now copy array input by default, to be consistent with Series
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sure sounds good. @zacharym-collins could you apply that suggestion. Also could you clarify that only numpy arrays and pandas ExtensionArrays are copied by default?