Skip to content

Commit dff37fe

Browse files
fix existing tests checking for index identity
1 parent 1a00586 commit dff37fe

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

pandas/tests/frame/methods/test_reindex.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def test_reindex_sparse(self):
599599
)
600600
tm.assert_frame_equal(result, expected)
601601

602-
def test_reindex(self, float_frame):
602+
def test_reindex(self, float_frame, using_copy_on_write):
603603
datetime_series = tm.makeTimeSeries(nper=30)
604604

605605
newFrame = float_frame.reindex(datetime_series.index)
@@ -639,7 +639,10 @@ def test_reindex(self, float_frame):
639639

640640
# Same index, copies values but not index if copy=False
641641
newFrame = float_frame.reindex(float_frame.index, copy=False)
642-
assert newFrame.index is float_frame.index
642+
if using_copy_on_write:
643+
assert newFrame.index.is_(float_frame.index)
644+
else:
645+
assert newFrame.index is float_frame.index
643646

644647
# length zero
645648
newFrame = float_frame.reindex([])

pandas/tests/frame/test_npfuncs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_np_sqrt(self, float_frame):
2222
with np.errstate(all="ignore"):
2323
result = np.sqrt(float_frame)
2424
assert isinstance(result, type(float_frame))
25-
assert result.index is float_frame.index
26-
assert result.columns is float_frame.columns
25+
assert result.index.is_(float_frame.index)
26+
assert result.columns.is_(float_frame.columns)
2727

2828
tm.assert_frame_equal(result, float_frame.apply(np.sqrt))
2929

pandas/tests/reshape/concat/test_index.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def test_concat_copy_index_frame(self, axis, using_copy_on_write):
114114
df = DataFrame([[1, 2], [3, 4]], columns=["a", "b"])
115115
comb = concat([df, df], axis=axis, copy=True)
116116
if not using_copy_on_write:
117-
assert comb.index is not df.index
118-
assert comb.columns is not df.columns
117+
assert not comb.index.is_(df.index)
118+
assert not comb.columns.is_(df.columns)
119119
elif axis in [0, "index"]:
120-
assert comb.index is not df.index
121-
assert comb.columns is df.columns
120+
assert not comb.index.is_(df.index)
121+
assert comb.columns.is_(df.columns)
122122
elif axis in [1, "columns"]:
123-
assert comb.index is df.index
124-
assert comb.columns is not df.columns
123+
assert comb.index.is_(df.index)
124+
assert not comb.columns.is_(df.columns)
125125

126126
def test_default_index(self):
127127
# is_series and ignore_index

pandas/tests/series/methods/test_align.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,20 @@ def test_align_nocopy(datetime_series, using_copy_on_write):
127127

128128
def test_align_same_index(datetime_series, using_copy_on_write):
129129
a, b = datetime_series.align(datetime_series, copy=False)
130-
assert a.index is datetime_series.index
131-
assert b.index is datetime_series.index
130+
if not using_copy_on_write:
131+
assert a.index is datetime_series.index
132+
assert b.index is datetime_series.index
133+
else:
134+
assert a.index.is_(datetime_series.index)
135+
assert b.index.is_(datetime_series.index)
132136

133137
a, b = datetime_series.align(datetime_series, copy=True)
134138
if not using_copy_on_write:
135139
assert a.index is not datetime_series.index
136140
assert b.index is not datetime_series.index
137141
else:
138-
assert a.index is datetime_series.index
139-
assert b.index is datetime_series.index
142+
assert a.index.is_(datetime_series.index)
143+
assert b.index.is_(datetime_series.index)
140144

141145

142146
def test_align_multiindex():

pandas/tests/series/test_constructors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,15 @@ def test_constructor_maskedarray_hardened(self):
628628
expected = Series([np.nan, np.nan, np.nan])
629629
tm.assert_series_equal(result, expected)
630630

631-
def test_series_ctor_plus_datetimeindex(self):
631+
def test_series_ctor_plus_datetimeindex(self, using_copy_on_write):
632632
rng = date_range("20090415", "20090519", freq="B")
633633
data = {k: 1 for k in rng}
634634

635635
result = Series(data, index=rng)
636-
assert result.index is rng
636+
if using_copy_on_write:
637+
assert result.index.is_(rng)
638+
else:
639+
assert result.index is rng
637640

638641
def test_constructor_default_index(self):
639642
s = Series([0, 1, 2])

pandas/tests/test_multilevel.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,26 @@ def test_reindex(self, multiindex_dataframe_random_data):
4646
tm.assert_frame_equal(reindexed, expected)
4747

4848
def test_reindex_preserve_levels(
49-
self, multiindex_year_month_day_dataframe_random_data
49+
self, multiindex_year_month_day_dataframe_random_data, using_copy_on_write
5050
):
5151
ymd = multiindex_year_month_day_dataframe_random_data
5252

5353
new_index = ymd.index[::10]
5454
chunk = ymd.reindex(new_index)
55-
assert chunk.index is new_index
55+
if using_copy_on_write:
56+
assert chunk.index.is_(new_index)
57+
else:
58+
assert chunk.index is new_index
5659

5760
chunk = ymd.loc[new_index]
5861
assert chunk.index.equals(new_index)
5962

6063
ymdT = ymd.T
6164
chunk = ymdT.reindex(columns=new_index)
62-
assert chunk.columns is new_index
65+
if using_copy_on_write:
66+
assert chunk.columns.is_(new_index)
67+
else:
68+
assert chunk.columns is new_index
6369

6470
chunk = ymdT.loc[:, new_index]
6571
assert chunk.columns.equals(new_index)

0 commit comments

Comments
 (0)