Skip to content

Commit a090024

Browse files
committed
TST: Verify that positional shifting works with duplicate columns (#9092)
1 parent b2b5dc3 commit a090024

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/frame/test_timeseries.py

+21
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,27 @@ def test_shift_empty(self):
266266

267267
assert_frame_equal(df, rs)
268268

269+
def test_shift_duplicate_columns(self):
270+
# GH 9092; verify that position-based shifting works
271+
# in the presence of duplicate columns
272+
column_lists = [list(range(5)), [1] * 5, [1, 1, 2, 2, 1]]
273+
data = np.random.randn(20, 5)
274+
275+
shifted = []
276+
for columns in column_lists:
277+
df = pd.DataFrame(data.copy(), columns=columns)
278+
for s in range(5):
279+
df.iloc[:, s] = df.iloc[:, s].shift(s + 1)
280+
df.columns = range(5)
281+
shifted.append(df)
282+
283+
# sanity check the base case
284+
nulls = shifted[0].isnull().sum()
285+
assert_series_equal(nulls, Series(range(1, 6)))
286+
# check all answers are the same
287+
assert_frame_equal(shifted[0], shifted[1])
288+
assert_frame_equal(shifted[0], shifted[2])
289+
269290
def test_tshift(self):
270291
# PeriodIndex
271292
ps = tm.makePeriodFrame()

0 commit comments

Comments
 (0)