@@ -263,77 +263,72 @@ def setup_method(self, method):
263
263
self .is_valid_objs = self .objs
264
264
self .not_valid_objs = []
265
265
266
- def test_none_comparison (self ):
267
-
266
+ def test_none_comparison (self , all_series_fixture ):
268
267
# bug brought up by #1079
269
268
# changed from TypeError in 0.17.0
270
- for o in self .is_valid_objs :
271
- if isinstance (o , Series ):
269
+ s = all_series_fixture
270
+ s [0 ] = np .nan
271
+
272
+ # noinspection PyComparisonWithNone
273
+ result = s == None # noqa
274
+ assert not result .iat [0 ]
275
+ assert not result .iat [1 ]
276
+
277
+ # noinspection PyComparisonWithNone
278
+ result = s != None # noqa
279
+ assert result .iat [0 ]
280
+ assert result .iat [1 ]
281
+
282
+ result = None == s # noqa
283
+ assert not result .iat [0 ]
284
+ assert not result .iat [1 ]
285
+
286
+ result = None != s # noqa
287
+ assert result .iat [0 ]
288
+ assert result .iat [1 ]
289
+
290
+ if (is_datetime64_dtype (s ) or
291
+ is_datetime64tz_dtype (s )):
292
+ # Following DatetimeIndex (and Timestamp) convention,
293
+ # inequality comparisons with Series[datetime64] raise
294
+ with pytest .raises (TypeError ):
295
+ None > s
296
+ with pytest .raises (TypeError ):
297
+ s > None
298
+ else :
299
+ result = None > s
300
+ assert not result .iat [0 ]
301
+ assert not result .iat [1 ]
272
302
273
- o [0 ] = np .nan
274
-
275
- # noinspection PyComparisonWithNone
276
- result = o == None # noqa
277
- assert not result .iat [0 ]
278
- assert not result .iat [1 ]
279
-
280
- # noinspection PyComparisonWithNone
281
- result = o != None # noqa
282
- assert result .iat [0 ]
283
- assert result .iat [1 ]
284
-
285
- result = None == o # noqa
286
- assert not result .iat [0 ]
287
- assert not result .iat [1 ]
288
-
289
- result = None != o # noqa
290
- assert result .iat [0 ]
291
- assert result .iat [1 ]
292
-
293
- if (is_datetime64_dtype (o ) or is_datetime64tz_dtype (o )):
294
- # Following DatetimeIndex (and Timestamp) convention,
295
- # inequality comparisons with Series[datetime64] raise
296
- with pytest .raises (TypeError ):
297
- None > o
298
- with pytest .raises (TypeError ):
299
- o > None
300
- else :
301
- result = None > o
302
- assert not result .iat [0 ]
303
- assert not result .iat [1 ]
303
+ result = s < None
304
+ assert not result .iat [0 ]
305
+ assert not result .iat [1 ]
304
306
305
- result = o < None
306
- assert not result .iat [0 ]
307
- assert not result .iat [1 ]
307
+ def test_ndarray_compat_properties (self , all_indices_and_series_fixture ):
308
308
309
- def test_ndarray_compat_properties (self ):
309
+ o = all_indices_and_series_fixture
310
+ # Check that we work.
311
+ for p in ['shape' , 'dtype' , 'T' , 'nbytes' ]:
312
+ assert getattr (o , p , None ) is not None
310
313
311
- for o in self . objs :
312
- # Check that we work.
313
- for p in [ 'shape' , 'dtype' , 'T' , 'nbytes' ] :
314
+ # deprecated properties
315
+ for p in [ 'flags' , 'strides' , 'itemsize' ]:
316
+ with tm . assert_produces_warning ( FutureWarning ) :
314
317
assert getattr (o , p , None ) is not None
315
318
316
- # deprecated properties
317
- for p in ['flags' , 'strides' , 'itemsize' ]:
318
- with tm .assert_produces_warning (FutureWarning ):
319
- assert getattr (o , p , None ) is not None
319
+ with tm .assert_produces_warning (FutureWarning ):
320
+ assert hasattr (o , 'base' )
320
321
321
- with tm .assert_produces_warning (FutureWarning ):
322
- assert hasattr (o , 'base' )
323
-
324
- # If we have a datetime-like dtype then needs a view to work
325
- # but the user is responsible for that
326
- try :
327
- with tm .assert_produces_warning (FutureWarning ):
328
- assert o .data is not None
329
- except ValueError :
330
- pass
322
+ # If we have a datetime-like dtype then needs a view to work
323
+ # but the user is responsible for that
324
+ with tm .assert_produces_warning (FutureWarning ):
325
+ assert o .data is not None
331
326
332
- with pytest .raises (ValueError ):
333
- o .item () # len > 1
327
+ with pytest .raises (ValueError ):
328
+ o .item () # len > 1
334
329
335
- assert o .ndim == 1
336
- assert o .size == len (o )
330
+ assert o .ndim == 1
331
+ assert o .size == len (o )
337
332
338
333
assert Index ([1 ]).item () == 1
339
334
assert Series ([1 ]).item () == 1
@@ -928,54 +923,53 @@ def test_validate_bool_args(self):
928
923
with pytest .raises (ValueError ):
929
924
self .int_series .drop_duplicates (inplace = value )
930
925
931
- def test_getitem (self ):
932
- for i in self . indexes :
933
- s = pd .Series (i )
926
+ def test_getitem (self , all_indices_fixture ):
927
+ idx = all_indices_fixture
928
+ s = pd .Series (idx )
934
929
935
- assert i [0 ] == s .iloc [0 ]
936
- assert i [5 ] == s .iloc [5 ]
937
- assert i [- 1 ] == s .iloc [- 1 ]
930
+ assert idx [0 ] == s .iloc [0 ]
931
+ assert idx [5 ] == s .iloc [5 ]
932
+ assert idx [- 1 ] == s .iloc [- 1 ]
938
933
939
- assert i [- 1 ] == i [9 ]
934
+ assert idx [- 1 ] == idx [9 ]
940
935
941
- with pytest .raises (IndexError ):
942
- i [20 ]
943
- with pytest .raises (IndexError ):
944
- s .iloc [20 ]
936
+ with pytest .raises (IndexError ):
937
+ idx [20 ]
938
+ with pytest .raises (IndexError ):
939
+ s .iloc [20 ]
945
940
946
941
@pytest .mark .parametrize ('indexer_klass' , [list , pd .Index ])
947
942
@pytest .mark .parametrize ('indexer' , [[True ] * 10 , [False ] * 10 ,
948
943
[True , False , True , True , False ,
949
944
False , True , True , False , True ]])
950
- def test_bool_indexing (self , indexer_klass , indexer ):
945
+ def test_bool_indexing (self , indexer_klass , indexer , all_indices_fixture ):
951
946
# GH 22533
952
- for idx in self . indexes :
953
- exp_idx = [i for i in range (len (indexer )) if indexer [i ]]
954
- tm .assert_index_equal (idx [indexer_klass (indexer )], idx [exp_idx ])
955
- s = pd .Series (idx )
956
- tm .assert_series_equal (s [indexer_klass (indexer )], s .iloc [exp_idx ])
947
+ idx = all_indices_fixture
948
+ exp_idx = [i for i in range (len (indexer )) if indexer [i ]]
949
+ tm .assert_index_equal (idx [indexer_klass (indexer )], idx [exp_idx ])
950
+ s = pd .Series (idx )
951
+ tm .assert_series_equal (s [indexer_klass (indexer )], s .iloc [exp_idx ])
957
952
958
953
959
954
class TestTranspose (Ops ):
960
955
errmsg = "the 'axes' parameter is not supported"
961
956
962
- def test_transpose (self ):
963
- for obj in self .objs :
964
- tm .assert_equal (obj .transpose (), obj )
965
-
966
- def test_transpose_non_default_axes (self ):
967
- for obj in self .objs :
968
- with pytest .raises (ValueError , match = self .errmsg ):
969
- obj .transpose (1 )
970
- with pytest .raises (ValueError , match = self .errmsg ):
971
- obj .transpose (axes = 1 )
972
-
973
- def test_numpy_transpose (self ):
974
- for obj in self .objs :
975
- tm .assert_equal (np .transpose (obj ), obj )
976
-
977
- with pytest .raises (ValueError , match = self .errmsg ):
978
- np .transpose (obj , axes = 1 )
957
+ def test_transpose (self , all_indices_and_series_fixture ):
958
+ obj = all_indices_and_series_fixture
959
+ tm .assert_equal (obj .transpose (), obj )
960
+
961
+ def test_transpose_non_default_axes (self , all_indices_and_series_fixture ):
962
+ obj = all_indices_and_series_fixture
963
+ with pytest .raises (ValueError , match = self .errmsg ):
964
+ obj .transpose (1 )
965
+ with pytest .raises (ValueError , match = self .errmsg ):
966
+ obj .transpose (axes = 1 )
967
+
968
+ def test_numpy_transpose (self , all_indices_and_series_fixture ):
969
+ obj = all_indices_and_series_fixture
970
+ tm .assert_equal (np .transpose (obj ), obj )
971
+ with pytest .raises (ValueError , match = self .errmsg ):
972
+ np .transpose (obj , axes = 1 )
979
973
980
974
981
975
class TestNoNewAttributesMixin (object ):
0 commit comments