Skip to content

Commit

Permalink
TST: Verify that positional shifting works with duplicate columns (pa…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsm054 authored and jreback committed Jul 2, 2017
1 parent e5fd3e0 commit 329fdaa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pandas/tests/frame/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ def test_shift_empty(self):

assert_frame_equal(df, rs)

def test_shift_duplicate_columns(self):
# GH 9092; verify that position-based shifting works
# in the presence of duplicate columns
column_lists = [list(range(5)), [1] * 5, [1, 1, 2, 2, 1]]
data = np.random.randn(20, 5)

shifted = []
for columns in column_lists:
df = pd.DataFrame(data.copy(), columns=columns)
for s in range(5):
df.iloc[:, s] = df.iloc[:, s].shift(s + 1)
df.columns = range(5)
shifted.append(df)

# sanity check the base case
nulls = shifted[0].isnull().sum()
assert_series_equal(nulls, Series(range(1, 6), dtype='int64'))

# check all answers are the same
assert_frame_equal(shifted[0], shifted[1])
assert_frame_equal(shifted[0], shifted[2])

def test_tshift(self):
# PeriodIndex
ps = tm.makePeriodFrame()
Expand Down

0 comments on commit 329fdaa

Please sign in to comment.