Skip to content

Commit 6ddf204

Browse files
Update pint_array.py
Make `ruff` and `black` happy. Signed-off-by: Michael Tiemann <[email protected]>
1 parent 5270a46 commit 6ddf204

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

pint_pandas/pint_array.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,9 @@ def quantify_nan(item, promote_to_ufloat):
552552

553553
if isinstance(master_scalar, _Quantity):
554554
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+
)
556558
else:
557559
promote_to_ufloat = False
558560
scalars = [quantify_nan(item, promote_to_ufloat) for item in scalars]
@@ -563,7 +565,14 @@ def quantify_nan(item, promote_to_ufloat):
563565
if HAS_UNCERTAINTIES:
564566
promote_to_ufloat = any([isinstance(item, UFloat) for item in scalars])
565567
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+
]
567576
return cls(scalars, dtype=dtype, copy=copy)
568577

569578
@classmethod
@@ -618,15 +627,15 @@ def factorize(
618627
# original ExtensionArray.
619628
# 2. ExtensionArray.factorize.
620629
# Complete control over factorization.
621-
if HAS_UNCERTAINTIES and self._data.dtype.kind == 'O':
630+
if HAS_UNCERTAINTIES and self._data.dtype.kind == "O":
622631
arr, na_value = self._values_for_factorize()
623632

624633
if not use_na_sentinel:
625634
# factorize can now handle differentiating various types of null values.
626635
# These can only occur when the array has object dtype.
627636
# However, for backwards compatibility we only use the null for the
628637
# provided dtype. This may be revisited in the future, see GH#48476.
629-
null_mask = isna(arr)
638+
null_mask = self.isna(arr)
630639
if null_mask.any():
631640
# Don't modify (potentially user-provided) array
632641
arr = np.where(null_mask, na_value, arr)
@@ -649,7 +658,7 @@ def _from_factorized(cls, values, original):
649658

650659
def _values_for_factorize(self):
651660
arr = self._data
652-
if HAS_UNCERTAINTIES and arr.dtype.kind == 'O':
661+
if HAS_UNCERTAINTIES and arr.dtype.kind == "O":
653662
unique_data = []
654663
for item in arr:
655664
if item not in unique_data:
@@ -681,7 +690,7 @@ def value_counts(self, dropna=True):
681690

682691
# compute counts on the data with no nans
683692
data = self._data
684-
if HAS_UNCERTAINTIES and data.dtype.kind == 'O':
693+
if HAS_UNCERTAINTIES and data.dtype.kind == "O":
685694
nafilt = unp.isnan(data)
686695
na_value = _ufloat_nan
687696
data = data[~nafilt]
@@ -715,12 +724,14 @@ def unique(self):
715724
from pandas import unique
716725

717726
data = self._data
718-
if HAS_UNCERTAINTIES and data.dtype.kind == 'O':
727+
if HAS_UNCERTAINTIES and data.dtype.kind == "O":
719728
unique_data = []
720729
for item in data:
721730
if item not in unique_data:
722731
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+
)
724735
return self._from_sequence(unique(data), dtype=self.dtype)
725736

726737
def __contains__(self, item) -> bool:

0 commit comments

Comments
 (0)