Skip to content

Commit 46f3270

Browse files
committed
clean up some idioms
1 parent d539290 commit 46f3270

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

pandas/core/arrays/_mask.py

-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111
class _MaskArray:
1212
_typ = "maskarray"
1313

14-
def _reduce(self, method, skipna=True, **kwargs):
15-
if skipna:
16-
arr = self[~self.isna()]
17-
else:
18-
arr = self
19-
20-
try:
21-
op = getattr(arr, method)
22-
except AttributeError:
23-
raise TypeError
24-
return op(**kwargs)
2514

2615

2716
def get_mask_array_type():

pandas/core/arrays/_numpy_bool.py

+12
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,15 @@ def sum(self, axis=None):
9797

9898
def take(self, indicies, **kwargs):
9999
return np.array(self, copy=False).take(indicies)
100+
101+
def _reduce(self, method, skipna=True, **kwargs):
102+
if skipna:
103+
arr = self[~self.isna()]
104+
else:
105+
arr = self
106+
107+
try:
108+
op = getattr(arr, method)
109+
except AttributeError:
110+
raise TypeError
111+
return op(**kwargs)

pandas/core/arrays/_pyarrow_bool.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,30 @@ def __invert__(self):
162162
)
163163

164164
def __or__(self, other):
165-
return np.array(
166-
self, copy=False).__or__(np.array(other, copy=False))
165+
return type(self).from_scalars(np.array(
166+
self, copy=False).__or__(np.array(other, copy=False)))
167167

168168
def __ior__(self, other):
169-
return np.array(self, copy=False) | np.array(other, copy=False)
169+
return type(self).from_scalars(
170+
np.array(self, copy=False) | np.array(other, copy=False))
170171

171172
def __and__(self, other):
172-
return np.array(self, copy=False).__and__(np.array(other, copy=False))
173+
return type(self).from_scalars(
174+
np.array(self, copy=False).__and__(np.array(other, copy=False)))
173175

174176
def __iand__(self, other):
175-
return np.array(self, copy=False) & (np.array(other, copy=False))
177+
return type(self).from_scalars(
178+
np.array(self, copy=False) & (np.array(other, copy=False)))
176179

177180
def __array__(self, dtype=None):
178181
return np.array(self._data, copy=False)
179182

183+
def any(self, axis=0, out=None):
184+
return self._data.to_pandas().any()
185+
186+
def all(self, axis=0, out=None):
187+
return self._data.to_pandas().all()
188+
180189
def _reduce(self, method, skipna=True, **kwargs):
181190
if skipna:
182191
arr = self[~self.isna()]
@@ -188,9 +197,3 @@ def _reduce(self, method, skipna=True, **kwargs):
188197
except AttributeError:
189198
raise TypeError
190199
return op(**kwargs)
191-
192-
def any(self, axis=0, out=None):
193-
return self._data.to_pandas().any()
194-
195-
def all(self, axis=0, out=None):
196-
return self._data.to_pandas().all()

0 commit comments

Comments
 (0)