-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport PR #51803 on branch 2.0.x (CoW: Add reference tracking to in…
…dex when created from series) (#52000)
- Loading branch information
Showing
13 changed files
with
330 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
Empty file.
This file contains 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,56 @@ | ||
import pytest | ||
|
||
from pandas import ( | ||
DatetimeIndex, | ||
Series, | ||
Timestamp, | ||
date_range, | ||
) | ||
import pandas._testing as tm | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"cons", | ||
[ | ||
lambda x: DatetimeIndex(x), | ||
lambda x: DatetimeIndex(DatetimeIndex(x)), | ||
], | ||
) | ||
def test_datetimeindex(using_copy_on_write, cons): | ||
dt = date_range("2019-12-31", periods=3, freq="D") | ||
ser = Series(dt) | ||
idx = cons(ser) | ||
expected = idx.copy(deep=True) | ||
ser.iloc[0] = Timestamp("2020-12-31") | ||
if using_copy_on_write: | ||
tm.assert_index_equal(idx, expected) | ||
|
||
|
||
def test_datetimeindex_tz_convert(using_copy_on_write): | ||
dt = date_range("2019-12-31", periods=3, freq="D", tz="Europe/Berlin") | ||
ser = Series(dt) | ||
idx = DatetimeIndex(ser).tz_convert("US/Eastern") | ||
expected = idx.copy(deep=True) | ||
ser.iloc[0] = Timestamp("2020-12-31", tz="Europe/Berlin") | ||
if using_copy_on_write: | ||
tm.assert_index_equal(idx, expected) | ||
|
||
|
||
def test_datetimeindex_tz_localize(using_copy_on_write): | ||
dt = date_range("2019-12-31", periods=3, freq="D") | ||
ser = Series(dt) | ||
idx = DatetimeIndex(ser).tz_localize("Europe/Berlin") | ||
expected = idx.copy(deep=True) | ||
ser.iloc[0] = Timestamp("2020-12-31") | ||
if using_copy_on_write: | ||
tm.assert_index_equal(idx, expected) | ||
|
||
|
||
def test_datetimeindex_isocalendar(using_copy_on_write): | ||
dt = date_range("2019-12-31", periods=3, freq="D") | ||
ser = Series(dt) | ||
df = DatetimeIndex(ser).isocalendar() | ||
expected = df.index.copy(deep=True) | ||
ser.iloc[0] = Timestamp("2020-12-31") | ||
if using_copy_on_write: | ||
tm.assert_index_equal(df.index, expected) |
Oops, something went wrong.