@@ -360,45 +360,19 @@ def get_op_from_name(self, op_name):
360
360
361
361
return op
362
362
363
- def _compare_other (self , data , op_name , other ):
364
- op = self .get_op_from_name (op_name )
365
-
366
- # array
367
- result = pd .Series (op (data , other ))
368
- expected = pd .Series (op (data ._data , other ), dtype = "boolean" )
369
-
370
- # fill the nan locations
371
- expected [data ._mask ] = np .nan
372
-
373
- tm .assert_series_equal (result , expected )
374
-
375
- # series
376
- s = pd .Series (data )
377
- result = op (s , other )
378
-
379
- expected = pd .Series (data ._data )
380
- expected = op (expected , other )
381
- expected = pd .Series (expected , dtype = "boolean" )
382
-
383
- # fill the nan locations
384
- expected [data ._mask ] = np .nan
363
+ def test_logical_length_mismatch_raises (self , all_logical_operators ):
364
+ op_name = all_logical_operators
365
+ a = pd .array ([True , False , None ], dtype = "boolean" )
366
+ msg = "Lengths must match to compare"
385
367
386
- tm .assert_series_equal (result , expected )
368
+ with pytest .raises (ValueError , match = msg ):
369
+ getattr (a , op_name )([True , False ])
387
370
388
- def test_scalar (self , data , all_logical_operators ):
389
- op_name = all_logical_operators
390
- self ._compare_other (data , op_name , True )
371
+ with pytest .raises (ValueError , match = msg ):
372
+ getattr (a , op_name )(np .array ([True , False ]))
391
373
392
- def test_array (self , data , all_logical_operators ):
393
- op_name = all_logical_operators
394
- if "or" in op_name :
395
- pytest .skip ("confusing" )
396
- other = pd .array ([True ] * len (data ), dtype = "boolean" )
397
- self ._compare_other (data , op_name , other )
398
- other = np .array ([True ] * len (data ))
399
- self ._compare_other (data , op_name , other )
400
- other = pd .Series ([True ] * len (data ), dtype = "boolean" )
401
- self ._compare_other (data , op_name , other )
374
+ with pytest .raises (ValueError , match = msg ):
375
+ getattr (a , op_name )(pd .array ([True , False ], dtype = "boolean" ))
402
376
403
377
def test_kleene_or (self ):
404
378
# A clear test of behavior.
@@ -431,27 +405,6 @@ def test_kleene_or_scalar(self, other, expected):
431
405
result = other | a
432
406
tm .assert_extension_array_equal (result , expected )
433
407
434
- @pytest .mark .parametrize (
435
- "left,right,expected" ,
436
- [
437
- ([True , False , None ], True , [True , True , True ]),
438
- ([True , False , None ], False , [True , False , None ]),
439
- ([True , False , None ], np .nan , [True , None , None ]),
440
- # TODO: pd.NA
441
- ],
442
- )
443
- def test_kleene_or_cases (self , left , right , expected ):
444
- if isinstance (left , list ):
445
- left = pd .array (left , dtype = "boolean" )
446
- if isinstance (right , list ):
447
- right = pd .array (right , dtype = "boolean" )
448
- expected = pd .array (expected , dtype = "boolean" )
449
- result = left | right
450
- tm .assert_extension_array_equal (result , expected )
451
-
452
- result = right | left
453
- tm .assert_extension_array_equal (result , expected )
454
-
455
408
def test_kleene_and (self ):
456
409
# A clear test of behavior.
457
410
a = pd .array ([True ] * 3 + [False ] * 3 + [None ] * 3 , dtype = "boolean" )
0 commit comments