Skip to content

Commit 25030fb

Browse files
committed
add specific join of two period-index dataframes
1 parent e45711f commit 25030fb

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pandas/tests/frame/test_join.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
import pytest
44
import numpy as np
55

6-
from pandas import DataFrame, Index
6+
from pandas import DataFrame, Index, PeriodIndex
77
from pandas.tests.frame.common import TestData
88
import pandas.util.testing as tm
99

10+
@pytest.fixture
11+
def frame_with_period_index():
12+
return DataFrame(
13+
data=np.arange(20).reshape(4,5),
14+
columns=list('abcde'),
15+
index=PeriodIndex(start='2000', freq='A', periods=4))
16+
1017

1118
@pytest.fixture
1219
def frame():
@@ -139,3 +146,22 @@ def test_join_overlap(frame):
139146

140147
# column order not necessarily sorted
141148
tm.assert_frame_equal(joined, expected.loc[:, joined.columns])
149+
150+
151+
def test_join_period_index(frame_with_period_index):
152+
other = frame_with_period_index.rename(
153+
columns=lambda x: '{key}{key}'.format(key=x))
154+
155+
joined_values = np.concatenate(
156+
[frame_with_period_index.values] * 2, axis=1)
157+
158+
joined_cols = frame_with_period_index.columns.append(other.columns)
159+
160+
joined = frame_with_period_index.join(other)
161+
expected = DataFrame(
162+
data=joined_values,
163+
columns=joined_cols,
164+
index=frame_with_period_index.index)
165+
166+
tm.assert_frame_equal(joined, expected)
167+

0 commit comments

Comments
 (0)