@@ -552,7 +552,9 @@ def quantify_nan(item, promote_to_ufloat):
552
552
553
553
if isinstance (master_scalar , _Quantity ):
554
554
if HAS_UNCERTAINTIES :
555
- promote_to_ufloat = any ([isinstance (item .m , UFloat ) for item in scalars ])
555
+ promote_to_ufloat = any (
556
+ [isinstance (item .m , UFloat ) for item in scalars ]
557
+ )
556
558
else :
557
559
promote_to_ufloat = False
558
560
scalars = [quantify_nan (item , promote_to_ufloat ) for item in scalars ]
@@ -563,7 +565,14 @@ def quantify_nan(item, promote_to_ufloat):
563
565
if HAS_UNCERTAINTIES :
564
566
promote_to_ufloat = any ([isinstance (item , UFloat ) for item in scalars ])
565
567
if promote_to_ufloat :
566
- scalars = [item if isinstance (item , UFloat ) else _ufloat_nan if np .isnan (item ) else ufloat (item , 0 ) for item in scalars ]
568
+ scalars = [
569
+ item
570
+ if isinstance (item , UFloat )
571
+ else _ufloat_nan
572
+ if np .isnan (item )
573
+ else ufloat (item , 0 )
574
+ for item in scalars
575
+ ]
567
576
return cls (scalars , dtype = dtype , copy = copy )
568
577
569
578
@classmethod
@@ -618,15 +627,15 @@ def factorize(
618
627
# original ExtensionArray.
619
628
# 2. ExtensionArray.factorize.
620
629
# Complete control over factorization.
621
- if HAS_UNCERTAINTIES and self ._data .dtype .kind == 'O' :
630
+ if HAS_UNCERTAINTIES and self ._data .dtype .kind == "O" :
622
631
arr , na_value = self ._values_for_factorize ()
623
632
624
633
if not use_na_sentinel :
625
634
# factorize can now handle differentiating various types of null values.
626
635
# These can only occur when the array has object dtype.
627
636
# However, for backwards compatibility we only use the null for the
628
637
# provided dtype. This may be revisited in the future, see GH#48476.
629
- null_mask = isna (arr )
638
+ null_mask = self . isna (arr )
630
639
if null_mask .any ():
631
640
# Don't modify (potentially user-provided) array
632
641
arr = np .where (null_mask , na_value , arr )
@@ -649,7 +658,7 @@ def _from_factorized(cls, values, original):
649
658
650
659
def _values_for_factorize (self ):
651
660
arr = self ._data
652
- if HAS_UNCERTAINTIES and arr .dtype .kind == 'O' :
661
+ if HAS_UNCERTAINTIES and arr .dtype .kind == "O" :
653
662
unique_data = []
654
663
for item in arr :
655
664
if item not in unique_data :
@@ -681,7 +690,7 @@ def value_counts(self, dropna=True):
681
690
682
691
# compute counts on the data with no nans
683
692
data = self ._data
684
- if HAS_UNCERTAINTIES and data .dtype .kind == 'O' :
693
+ if HAS_UNCERTAINTIES and data .dtype .kind == "O" :
685
694
nafilt = unp .isnan (data )
686
695
na_value = _ufloat_nan
687
696
data = data [~ nafilt ]
@@ -715,12 +724,14 @@ def unique(self):
715
724
from pandas import unique
716
725
717
726
data = self ._data
718
- if HAS_UNCERTAINTIES and data .dtype .kind == 'O' :
727
+ if HAS_UNCERTAINTIES and data .dtype .kind == "O" :
719
728
unique_data = []
720
729
for item in data :
721
730
if item not in unique_data :
722
731
unique_data .append (item )
723
- return self ._from_sequence (pd .array (unique_data , dtype = data .dtype ), dtype = self .dtype )
732
+ return self ._from_sequence (
733
+ pd .array (unique_data , dtype = data .dtype ), dtype = self .dtype
734
+ )
724
735
return self ._from_sequence (unique (data ), dtype = self .dtype )
725
736
726
737
def __contains__ (self , item ) -> bool :
0 commit comments