2424
2525import pandas .util .testing as tm
2626
27- from pandas .tests .frame .common import TestData
28-
2927
3028class SharedWithSparse (object ):
3129 """
@@ -43,57 +41,57 @@ def _assert_series_equal(self, left, right):
4341 """Dispatch to series class dependent assertion"""
4442 raise NotImplementedError
4543
46- def test_copy_index_name_checking (self ):
44+ def test_copy_index_name_checking (self , float_frame ):
4745 # don't want to be able to modify the index stored elsewhere after
4846 # making a copy
4947 for attr in ('index' , 'columns' ):
50- ind = getattr (self . frame , attr )
48+ ind = getattr (float_frame , attr )
5149 ind .name = None
52- cp = self . frame .copy ()
50+ cp = float_frame .copy ()
5351 getattr (cp , attr ).name = 'foo'
54- assert getattr (self . frame , attr ).name is None
52+ assert getattr (float_frame , attr ).name is None
5553
56- def test_getitem_pop_assign_name (self ):
57- s = self . frame ['A' ]
54+ def test_getitem_pop_assign_name (self , float_frame ):
55+ s = float_frame ['A' ]
5856 assert s .name == 'A'
5957
60- s = self . frame .pop ('A' )
58+ s = float_frame .pop ('A' )
6159 assert s .name == 'A'
6260
63- s = self . frame .loc [:, 'B' ]
61+ s = float_frame .loc [:, 'B' ]
6462 assert s .name == 'B'
6563
6664 s2 = s .loc [:]
6765 assert s2 .name == 'B'
6866
69- def test_get_value (self ):
70- for idx in self . frame .index :
71- for col in self . frame .columns :
67+ def test_get_value (self , float_frame ):
68+ for idx in float_frame .index :
69+ for col in float_frame .columns :
7270 with tm .assert_produces_warning (FutureWarning ,
7371 check_stacklevel = False ):
74- result = self . frame .get_value (idx , col )
75- expected = self . frame [col ][idx ]
72+ result = float_frame .get_value (idx , col )
73+ expected = float_frame [col ][idx ]
7674 tm .assert_almost_equal (result , expected )
7775
78- def test_add_prefix_suffix (self ):
79- with_prefix = self . frame .add_prefix ('foo#' )
80- expected = pd .Index (['foo#%s' % c for c in self . frame .columns ])
76+ def test_add_prefix_suffix (self , float_frame ):
77+ with_prefix = float_frame .add_prefix ('foo#' )
78+ expected = pd .Index (['foo#%s' % c for c in float_frame .columns ])
8179 tm .assert_index_equal (with_prefix .columns , expected )
8280
83- with_suffix = self . frame .add_suffix ('#foo' )
84- expected = pd .Index (['%s#foo' % c for c in self . frame .columns ])
81+ with_suffix = float_frame .add_suffix ('#foo' )
82+ expected = pd .Index (['%s#foo' % c for c in float_frame .columns ])
8583 tm .assert_index_equal (with_suffix .columns , expected )
8684
87- with_pct_prefix = self . frame .add_prefix ('%' )
88- expected = pd .Index (['%{}' .format (c ) for c in self . frame .columns ])
85+ with_pct_prefix = float_frame .add_prefix ('%' )
86+ expected = pd .Index (['%{}' .format (c ) for c in float_frame .columns ])
8987 tm .assert_index_equal (with_pct_prefix .columns , expected )
9088
91- with_pct_suffix = self . frame .add_suffix ('%' )
92- expected = pd .Index (['{}%' .format (c ) for c in self . frame .columns ])
89+ with_pct_suffix = float_frame .add_suffix ('%' )
90+ expected = pd .Index (['{}%' .format (c ) for c in float_frame .columns ])
9391 tm .assert_index_equal (with_pct_suffix .columns , expected )
9492
95- def test_get_axis (self ):
96- f = self . frame
93+ def test_get_axis (self , float_frame ):
94+ f = float_frame
9795 assert f ._get_axis_number (0 ) == 0
9896 assert f ._get_axis_number (1 ) == 1
9997 assert f ._get_axis_number ('index' ) == 0
@@ -118,13 +116,13 @@ def test_get_axis(self):
118116 tm .assert_raises_regex (ValueError , 'No axis named' ,
119117 f ._get_axis_number , None )
120118
121- def test_keys (self ):
122- getkeys = self . frame .keys
123- assert getkeys () is self . frame .columns
119+ def test_keys (self , float_frame ):
120+ getkeys = float_frame .keys
121+ assert getkeys () is float_frame .columns
124122
125- def test_column_contains_typeerror (self ):
123+ def test_column_contains_typeerror (self , float_frame ):
126124 try :
127- self . frame . columns in self . frame
125+ float_frame . columns in float_frame
128126 except TypeError :
129127 pass
130128
@@ -146,40 +144,40 @@ def test_tab_completion(self):
146144 assert key not in dir (df )
147145 assert isinstance (df .__getitem__ ('A' ), pd .DataFrame )
148146
149- def test_not_hashable (self ):
147+ def test_not_hashable (self , empty_frame ):
150148 df = self .klass ([1 ])
151149 pytest .raises (TypeError , hash , df )
152- pytest .raises (TypeError , hash , self . empty )
150+ pytest .raises (TypeError , hash , empty_frame )
153151
154152 def test_new_empty_index (self ):
155153 df1 = self .klass (randn (0 , 3 ))
156154 df2 = self .klass (randn (0 , 3 ))
157155 df1 .index .name = 'foo'
158156 assert df2 .index .name is None
159157
160- def test_array_interface (self ):
158+ def test_array_interface (self , float_frame ):
161159 with np .errstate (all = 'ignore' ):
162- result = np .sqrt (self . frame )
163- assert isinstance (result , type (self . frame ))
164- assert result .index is self . frame .index
165- assert result .columns is self . frame .columns
160+ result = np .sqrt (float_frame )
161+ assert isinstance (result , type (float_frame ))
162+ assert result .index is float_frame .index
163+ assert result .columns is float_frame .columns
166164
167- self ._assert_frame_equal (result , self . frame .apply (np .sqrt ))
165+ self ._assert_frame_equal (result , float_frame .apply (np .sqrt ))
168166
169- def test_get_agg_axis (self ):
170- cols = self . frame ._get_agg_axis (0 )
171- assert cols is self . frame .columns
167+ def test_get_agg_axis (self , float_frame ):
168+ cols = float_frame ._get_agg_axis (0 )
169+ assert cols is float_frame .columns
172170
173- idx = self . frame ._get_agg_axis (1 )
174- assert idx is self . frame .index
171+ idx = float_frame ._get_agg_axis (1 )
172+ assert idx is float_frame .index
175173
176- pytest .raises (ValueError , self . frame ._get_agg_axis , 2 )
174+ pytest .raises (ValueError , float_frame ._get_agg_axis , 2 )
177175
178- def test_nonzero (self ):
179- assert self . empty .empty
176+ def test_nonzero (self , float_frame , float_string_frame , empty_frame ):
177+ assert empty_frame .empty
180178
181- assert not self . frame .empty
182- assert not self . mixed_frame .empty
179+ assert not float_frame .empty
180+ assert not float_string_frame .empty
183181
184182 # corner case
185183 df = DataFrame ({'A' : [1. , 2. , 3. ],
@@ -202,16 +200,16 @@ def test_items(self):
202200 assert isinstance (v , Series )
203201 assert (df [k ] == v ).all ()
204202
205- def test_iter (self ):
206- assert tm .equalContents (list (self . frame ), self . frame .columns )
203+ def test_iter (self , float_frame ):
204+ assert tm .equalContents (list (float_frame ), float_frame .columns )
207205
208- def test_iterrows (self ):
209- for k , v in self . frame .iterrows ():
210- exp = self . frame .loc [k ]
206+ def test_iterrows (self , float_frame , float_string_frame ):
207+ for k , v in float_frame .iterrows ():
208+ exp = float_frame .loc [k ]
211209 self ._assert_series_equal (v , exp )
212210
213- for k , v in self . mixed_frame .iterrows ():
214- exp = self . mixed_frame .loc [k ]
211+ for k , v in float_string_frame .iterrows ():
212+ exp = float_string_frame .loc [k ]
215213 self ._assert_series_equal (v , exp )
216214
217215 def test_iterrows_iso8601 (self ):
@@ -226,11 +224,11 @@ def test_iterrows_iso8601(self):
226224 exp = s .loc [k ]
227225 self ._assert_series_equal (v , exp )
228226
229- def test_itertuples (self ):
230- for i , tup in enumerate (self . frame .itertuples ()):
227+ def test_itertuples (self , float_frame ):
228+ for i , tup in enumerate (float_frame .itertuples ()):
231229 s = self .klass ._constructor_sliced (tup [1 :])
232230 s .name = tup [0 ]
233- expected = self . frame .iloc [i , :].reset_index (drop = True )
231+ expected = float_frame .iloc [i , :].reset_index (drop = True )
234232 self ._assert_series_equal (s , expected )
235233
236234 df = self .klass ({'floats' : np .random .randn (5 ),
@@ -289,11 +287,11 @@ def test_sequence_like_with_categorical(self):
289287 for c , col in df .iteritems ():
290288 str (s )
291289
292- def test_len (self ):
293- assert len (self . frame ) == len (self . frame .index )
290+ def test_len (self , float_frame ):
291+ assert len (float_frame ) == len (float_frame .index )
294292
295- def test_values (self ):
296- frame = self . frame
293+ def test_values (self , float_frame , float_string_frame ):
294+ frame = float_frame
297295 arr = frame .values
298296
299297 frame_cols = frame .columns
@@ -306,20 +304,20 @@ def test_values(self):
306304 assert value == frame [col ][i ]
307305
308306 # mixed type
309- arr = self . mixed_frame [['foo' , 'A' ]].values
307+ arr = float_string_frame [['foo' , 'A' ]].values
310308 assert arr [0 , 0 ] == 'bar'
311309
312- df = self .klass ({'real ' : [1 , 2 , 3 ], 'complex ' : [1j , 2j , 3j ]})
310+ df = self .klass ({'complex ' : [1j , 2j , 3j ], 'real ' : [1 , 2 , 3 ]})
313311 arr = df .values
314312 assert arr [0 , 0 ] == 1j
315313
316314 # single block corner case
317- arr = self . frame [['A' , 'B' ]].values
318- expected = self . frame .reindex (columns = ['A' , 'B' ]).values
315+ arr = float_frame [['A' , 'B' ]].values
316+ expected = float_frame .reindex (columns = ['A' , 'B' ]).values
319317 assert_almost_equal (arr , expected )
320318
321- def test_transpose (self ):
322- frame = self . frame
319+ def test_transpose (self , float_frame ):
320+ frame = float_frame
323321 dft = frame .T
324322 for idx , series in compat .iteritems (dft ):
325323 for col , value in compat .iteritems (series ):
@@ -343,8 +341,8 @@ def test_swapaxes(self):
343341 self ._assert_frame_equal (df , df .swapaxes (0 , 0 ))
344342 pytest .raises (ValueError , df .swapaxes , 2 , 5 )
345343
346- def test_axis_aliases (self ):
347- f = self . frame
344+ def test_axis_aliases (self , float_frame ):
345+ f = float_frame
348346
349347 # reg name
350348 expected = f .sum (axis = 0 )
@@ -361,23 +359,23 @@ def test_class_axis(self):
361359 assert pydoc .getdoc (DataFrame .index )
362360 assert pydoc .getdoc (DataFrame .columns )
363361
364- def test_more_values (self ):
365- values = self . mixed_frame .values
366- assert values .shape [1 ] == len (self . mixed_frame .columns )
362+ def test_more_values (self , float_string_frame ):
363+ values = float_string_frame .values
364+ assert values .shape [1 ] == len (float_string_frame .columns )
367365
368- def test_repr_with_mi_nat (self ):
366+ def test_repr_with_mi_nat (self , float_string_frame ):
369367 df = self .klass ({'X' : [1 , 2 ]},
370368 index = [[pd .NaT , pd .Timestamp ('20130101' )], ['a' , 'b' ]])
371369 res = repr (df )
372370 exp = ' X\n NaT a 1\n 2013-01-01 b 2'
373371 assert res == exp
374372
375- def test_iteritems_names (self ):
376- for k , v in compat .iteritems (self . mixed_frame ):
373+ def test_iteritems_names (self , float_string_frame ):
374+ for k , v in compat .iteritems (float_string_frame ):
377375 assert v .name == k
378376
379- def test_series_put_names (self ):
380- series = self . mixed_frame ._series
377+ def test_series_put_names (self , float_string_frame ):
378+ series = float_string_frame ._series
381379 for k , v in compat .iteritems (series ):
382380 assert v .name == k
383381
@@ -408,36 +406,37 @@ def test_with_datetimelikes(self):
408406 tm .assert_series_equal (result , expected )
409407
410408
411- class TestDataFrameMisc (SharedWithSparse , TestData ):
409+ class TestDataFrameMisc (SharedWithSparse ):
412410
413411 klass = DataFrame
414412 # SharedWithSparse tests use generic, klass-agnostic assertion
415413 _assert_frame_equal = staticmethod (assert_frame_equal )
416414 _assert_series_equal = staticmethod (assert_series_equal )
417415
418- def test_values (self ):
419- self . frame .values [:, 0 ] = 5.
420- assert (self . frame .values [:, 0 ] == 5 ).all ()
416+ def test_values (self , float_frame ):
417+ float_frame .values [:, 0 ] = 5.
418+ assert (float_frame .values [:, 0 ] == 5 ).all ()
421419
422- def test_as_matrix_deprecated (self ):
420+ def test_as_matrix_deprecated (self , float_frame ):
423421 # GH18458
424422 with tm .assert_produces_warning (FutureWarning ):
425- result = self .frame .as_matrix (columns = self .frame .columns .tolist ())
426- expected = self .frame .values
423+ cols = float_frame .columns .tolist ()
424+ result = float_frame .as_matrix (columns = cols )
425+ expected = float_frame .values
427426 tm .assert_numpy_array_equal (result , expected )
428427
429- def test_deepcopy (self ):
430- cp = deepcopy (self . frame )
428+ def test_deepcopy (self , float_frame ):
429+ cp = deepcopy (float_frame )
431430 series = cp ['A' ]
432431 series [:] = 10
433432 for idx , value in compat .iteritems (series ):
434- assert self . frame ['A' ][idx ] != value
433+ assert float_frame ['A' ][idx ] != value
435434
436- def test_transpose_get_view (self ):
437- dft = self . frame .T
435+ def test_transpose_get_view (self , float_frame ):
436+ dft = float_frame .T
438437 dft .values [:, 5 :10 ] = 5
439438
440- assert (self . frame .values [5 :10 ] == 5 ).all ()
439+ assert (float_frame .values [5 :10 ] == 5 ).all ()
441440
442441 def test_inplace_return_self (self ):
443442 # re #1893
0 commit comments