4
4
import pytest
5
5
6
6
from pandas import DataFrame , Index , period_range
7
- from pandas .tests .frame .common import TestData
8
7
import pandas .util .testing as tm
9
8
10
9
@@ -16,11 +15,6 @@ def frame_with_period_index():
16
15
index = period_range (start = '2000' , freq = 'A' , periods = 4 ))
17
16
18
17
19
- @pytest .fixture
20
- def frame ():
21
- return TestData ().frame
22
-
23
-
24
18
@pytest .fixture
25
19
def left ():
26
20
return DataFrame ({'a' : [20 , 10 , 0 ]}, index = [2 , 1 , 0 ])
@@ -63,11 +57,11 @@ def test_join(left, right, how, sort, expected):
63
57
tm .assert_frame_equal (result , expected )
64
58
65
59
66
- def test_join_index (frame ):
60
+ def test_join_index (float_frame ):
67
61
# left / right
68
62
69
- f = frame .loc [frame .index [:10 ], ['A' , 'B' ]]
70
- f2 = frame .loc [frame .index [5 :], ['C' , 'D' ]].iloc [::- 1 ]
63
+ f = float_frame .loc [float_frame .index [:10 ], ['A' , 'B' ]]
64
+ f2 = float_frame .loc [float_frame .index [5 :], ['C' , 'D' ]].iloc [::- 1 ]
71
65
72
66
joined = f .join (f2 )
73
67
tm .assert_index_equal (f .index , joined .index )
@@ -91,7 +85,7 @@ def test_join_index(frame):
91
85
# outer
92
86
93
87
joined = f .join (f2 , how = 'outer' )
94
- tm .assert_index_equal (joined .index , frame .index .sort_values ())
88
+ tm .assert_index_equal (joined .index , float_frame .index .sort_values ())
95
89
tm .assert_index_equal (joined .columns , expected_columns )
96
90
97
91
with pytest .raises (ValueError , match = 'join method' ):
@@ -101,16 +95,16 @@ def test_join_index(frame):
101
95
msg = 'columns overlap but no suffix'
102
96
for how in ('outer' , 'left' , 'inner' ):
103
97
with pytest .raises (ValueError , match = msg ):
104
- frame .join (frame , how = how )
98
+ float_frame .join (float_frame , how = how )
105
99
106
100
107
- def test_join_index_more (frame ):
108
- af = frame .loc [:, ['A' , 'B' ]]
109
- bf = frame .loc [::2 , ['C' , 'D' ]]
101
+ def test_join_index_more (float_frame ):
102
+ af = float_frame .loc [:, ['A' , 'B' ]]
103
+ bf = float_frame .loc [::2 , ['C' , 'D' ]]
110
104
111
105
expected = af .copy ()
112
- expected ['C' ] = frame ['C' ][::2 ]
113
- expected ['D' ] = frame ['D' ][::2 ]
106
+ expected ['C' ] = float_frame ['C' ][::2 ]
107
+ expected ['D' ] = float_frame ['D' ][::2 ]
114
108
115
109
result = af .join (bf )
116
110
tm .assert_frame_equal (result , expected )
@@ -122,28 +116,28 @@ def test_join_index_more(frame):
122
116
tm .assert_frame_equal (result , expected .loc [:, result .columns ])
123
117
124
118
125
- def test_join_index_series (frame ):
126
- df = frame .copy ()
127
- s = df .pop (frame .columns [- 1 ])
119
+ def test_join_index_series (float_frame ):
120
+ df = float_frame .copy ()
121
+ s = df .pop (float_frame .columns [- 1 ])
128
122
joined = df .join (s )
129
123
130
124
# TODO should this check_names ?
131
- tm .assert_frame_equal (joined , frame , check_names = False )
125
+ tm .assert_frame_equal (joined , float_frame , check_names = False )
132
126
133
127
s .name = None
134
128
with pytest .raises (ValueError , match = 'must have a name' ):
135
129
df .join (s )
136
130
137
131
138
- def test_join_overlap (frame ):
139
- df1 = frame .loc [:, ['A' , 'B' , 'C' ]]
140
- df2 = frame .loc [:, ['B' , 'C' , 'D' ]]
132
+ def test_join_overlap (float_frame ):
133
+ df1 = float_frame .loc [:, ['A' , 'B' , 'C' ]]
134
+ df2 = float_frame .loc [:, ['B' , 'C' , 'D' ]]
141
135
142
136
joined = df1 .join (df2 , lsuffix = '_df1' , rsuffix = '_df2' )
143
137
df1_suf = df1 .loc [:, ['B' , 'C' ]].add_suffix ('_df1' )
144
138
df2_suf = df2 .loc [:, ['B' , 'C' ]].add_suffix ('_df2' )
145
139
146
- no_overlap = frame .loc [:, ['A' , 'D' ]]
140
+ no_overlap = float_frame .loc [:, ['A' , 'D' ]]
147
141
expected = df1_suf .join (df2_suf ).join (no_overlap )
148
142
149
143
# column order not necessarily sorted
0 commit comments