@@ -162,10 +162,9 @@ def test_scalar_non_numeric(self, index_func, klass):
162
162
s2 .loc [3.0 ] = 10
163
163
assert s2 .index .is_object ()
164
164
165
- for idxr in [lambda x : x ]:
166
- s2 = s .copy ()
167
- idxr (s2 )[3.0 ] = 0
168
- assert s2 .index .is_object ()
165
+ s2 = s .copy ()
166
+ s2 [3.0 ] = 0
167
+ assert s2 .index .is_object ()
169
168
170
169
@pytest .mark .parametrize (
171
170
"index_func" ,
@@ -250,12 +249,7 @@ def test_scalar_integer(self, index_func, klass):
250
249
251
250
# integer index
252
251
i = index_func (5 )
253
-
254
- if klass is Series :
255
- # TODO: Should we be passing index=i here?
256
- obj = Series (np .arange (len (i )))
257
- else :
258
- obj = DataFrame (np .random .randn (len (i ), len (i )), index = i , columns = i )
252
+ obj = gen_obj (klass , i )
259
253
260
254
# coerce to equal int
261
255
for idxr , getitem in [(lambda x : x .loc , False ), (lambda x : x , True )]:
@@ -313,7 +307,7 @@ def test_scalar_float(self, klass):
313
307
result = idxr (s2 )[indexer ]
314
308
self .check (result , s , 3 , getitem )
315
309
316
- # random integer is a KeyError
310
+ # random float is a KeyError
317
311
with pytest .raises (KeyError , match = r"^3\.5$" ):
318
312
idxr (s )[3.5 ]
319
313
@@ -429,15 +423,6 @@ def test_slice_integer(self):
429
423
indexer = slice (3 , 5 )
430
424
self .check (result , s , indexer , False )
431
425
432
- # positional indexing
433
- msg = (
434
- "cannot do slice indexing "
435
- fr"on { type (index ).__name__ } with these indexers \[(3|4)\.0\] of "
436
- "type float"
437
- )
438
- with pytest .raises (TypeError , match = msg ):
439
- s [l ]
440
-
441
426
# getitem out-of-bounds
442
427
for l in [slice (- 6 , 6 ), slice (- 6.0 , 6.0 )]:
443
428
@@ -485,23 +470,6 @@ def test_slice_integer(self):
485
470
with pytest .raises (TypeError , match = msg ):
486
471
s [l ]
487
472
488
- # setitem
489
- for l in [slice (3.0 , 4 ), slice (3 , 4.0 ), slice (3.0 , 4.0 )]:
490
-
491
- sc = s .copy ()
492
- sc .loc [l ] = 0
493
- result = sc .loc [l ].values .ravel ()
494
- assert (result == 0 ).all ()
495
-
496
- # positional indexing
497
- msg = (
498
- "cannot do slice indexing "
499
- fr"on { type (index ).__name__ } with these indexers \[(3|4)\.0\] of "
500
- "type float"
501
- )
502
- with pytest .raises (TypeError , match = msg ):
503
- s [l ] = 0
504
-
505
473
@pytest .mark .parametrize ("l" , [slice (2 , 4.0 ), slice (2.0 , 4 ), slice (2.0 , 4.0 )])
506
474
def test_integer_positional_indexing (self , l ):
507
475
""" make sure that we are raising on positional indexing
@@ -584,22 +552,34 @@ def test_slice_integer_frame_getitem(self, index_func):
584
552
with pytest .raises (TypeError , match = msg ):
585
553
s [l ]
586
554
555
+ @pytest .mark .parametrize ("l" , [slice (3.0 , 4 ), slice (3 , 4.0 ), slice (3.0 , 4.0 )])
556
+ @pytest .mark .parametrize (
557
+ "index_func" , [tm .makeIntIndex , tm .makeRangeIndex ],
558
+ )
559
+ def test_float_slice_getitem_with_integer_index_raises (self , l , index_func ):
560
+
561
+ # similar to above, but on the getitem dim (of a DataFrame)
562
+ index = index_func (5 )
563
+
564
+ s = DataFrame (np .random .randn (5 , 2 ), index = index )
565
+
587
566
# setitem
588
- for l in [slice (3.0 , 4 ), slice (3 , 4.0 ), slice (3.0 , 4.0 )]:
567
+ sc = s .copy ()
568
+ sc .loc [l ] = 0
569
+ result = sc .loc [l ].values .ravel ()
570
+ assert (result == 0 ).all ()
589
571
590
- sc = s .copy ()
591
- sc .loc [l ] = 0
592
- result = sc .loc [l ].values .ravel ()
593
- assert (result == 0 ).all ()
572
+ # positional indexing
573
+ msg = (
574
+ "cannot do slice indexing "
575
+ fr"on { type (index ).__name__ } with these indexers \[(3|4)\.0\] of "
576
+ "type float"
577
+ )
578
+ with pytest .raises (TypeError , match = msg ):
579
+ s [l ] = 0
594
580
595
- # positional indexing
596
- msg = (
597
- "cannot do slice indexing "
598
- fr"on { type (index ).__name__ } with these indexers \[(3|4)\.0\] of "
599
- "type float"
600
- )
601
- with pytest .raises (TypeError , match = msg ):
602
- s [l ] = 0
581
+ with pytest .raises (TypeError , match = msg ):
582
+ s [l ]
603
583
604
584
@pytest .mark .parametrize ("l" , [slice (3.0 , 4 ), slice (3 , 4.0 ), slice (3.0 , 4.0 )])
605
585
@pytest .mark .parametrize ("klass" , [Series , DataFrame ])
@@ -614,10 +594,9 @@ def test_slice_float(self, l, klass):
614
594
615
595
# getitem
616
596
result = idxr (s )[l ]
617
- if isinstance (s , Series ):
618
- tm .assert_series_equal (result , expected )
619
- else :
620
- tm .assert_frame_equal (result , expected )
597
+ assert isinstance (result , type (s ))
598
+ tm .assert_equal (result , expected )
599
+
621
600
# setitem
622
601
s2 = s .copy ()
623
602
idxr (s2 )[l ] = 0
0 commit comments