1
- """A boolean mask interace .
1
+ """A boolean mask intferace .
2
2
3
3
This module provides an interface to a numpy / pyarrow boolean mask.
4
4
This is limited as not all of the implementations can hold NA, so
11
11
12
12
from pandas import compat
13
13
from pandas .api .extensions import ExtensionDtype
14
+ from pandas .api .types import is_scalar
14
15
from pandas .core .arrays .base import ExtensionArray
15
16
from pandas .core .missing import isna
16
17
@@ -39,7 +40,7 @@ def __eq__(self, other):
39
40
# compare == to np.dtype('bool')
40
41
if isinstance (other , compat .string_types ):
41
42
return other == self .name
42
- elif other is self :
43
+ elif isinstance ( other , type ( self )) :
43
44
return True
44
45
elif isinstance (other , np .dtype ):
45
46
return other == 'bool'
@@ -55,10 +56,6 @@ class BoolArray(ExtensionArray):
55
56
def _from_sequence (cls , scalars , dtype = None , copy = False ):
56
57
return cls .from_scalars (scalars )
57
58
58
- @property
59
- def dtype (self ):
60
- return self ._dtype
61
-
62
59
@property
63
60
def size (self ):
64
61
return len (self )
@@ -94,13 +91,21 @@ def __iand__(self, other):
94
91
return type (self ).from_scalars (
95
92
np .array (self , copy = False ) & (np .array (other , copy = False )))
96
93
94
+ def __getitem__ (self , item ):
95
+ arr = np .array (self , copy = False )
96
+ if is_scalar (item ):
97
+ return arr [item ]
98
+ else :
99
+ arr = arr [item ]
100
+ return type (self ).from_scalars (arr )
101
+
97
102
def view (self , dtype = None ):
98
103
arr = np .array (self ._data , copy = False )
99
104
if dtype is not None :
100
105
arr = arr .view (dtype = dtype )
101
106
return arr
102
107
103
- def sum (self , axis = None ):
108
+ def sum (self , axis = None , min_count = None ):
104
109
return np .array (self , copy = False ).sum ()
105
110
106
111
def copy (self , deep = False ):
@@ -120,9 +125,11 @@ def _reduce(self, method, skipna=True, **kwargs):
120
125
arr = self [~ self .isna ()]
121
126
else :
122
127
arr = self
123
-
128
+ # we only allow explicity defined methods
129
+ # ndarrays actually support: mean, var, prod, min, max
124
130
try :
125
131
op = getattr (arr , method )
132
+ return op ()
126
133
except AttributeError :
127
- raise TypeError
128
- return op ( ** kwargs )
134
+ pass
135
+ raise TypeError
0 commit comments