Skip to content

Commit 03dd397

Browse files
committed
rename to private namespaces
1 parent d262a62 commit 03dd397

File tree

5 files changed

+109
-117
lines changed

5 files changed

+109
-117
lines changed

pandas/core/arrays/_mask.py

Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
"""A boolean mask interace.
22
3-
This module provide a numpy-like mask; it can be optionally backed
4-
by pyarrow.
3+
This module provides an interface to a numpy / pyarrow boolean mask.
54
"""
65

7-
import numpy as np
8-
from pandas.core.arrays import ExtensionArray
9-
106

117
class _MaskArray:
128
_typ = "maskarray"
@@ -24,112 +20,20 @@ def _reduce(self, method, skipna=True, **kwargs):
2420
return op(**kwargs)
2521

2622

27-
# TODO: The NumpyBoolArray should actually be a full EA.
28-
29-
class NumpyBoolArray(ExtensionArray):
30-
"""Generic class which can be used to represent missing data.
31-
"""
32-
33-
@property
34-
def dtype(self):
35-
return np.dtype('bool')
36-
37-
@classmethod
38-
def _from_sequence(cls, scalars, dtype=None, copy=False):
39-
arr = np.asarray(scalars).astype(np.bool_, copy=False)
40-
return cls(arr, copy=copy)
41-
42-
def __init__(self, mask, copy=True):
43-
"""
44-
Parameters
45-
----------
46-
mask : numpy array
47-
Mask of missing values.
48-
"""
49-
assert isinstance(mask, np.ndarray)
50-
assert mask.dtype == np.bool_
51-
52-
if copy:
53-
mask = mask.copy()
54-
self._data = mask
55-
56-
def __getitem__(self, key):
57-
return self._data[key]
58-
59-
def __setitem__(self, key, value):
60-
self._data[key] = value
61-
62-
def __len__(self):
63-
return len(self._data)
64-
65-
def __eq__(self, other):
66-
return np.array(self, copy=False) == np.array(other, copy=False)
67-
68-
def __array__(self, dtype=None):
69-
return self._data
70-
71-
def __iter__(self):
72-
return iter(self._data)
73-
74-
def __invert__(self):
75-
return type(self)(~self._data)
76-
77-
def __or__(self, other):
78-
return np.array(
79-
self, copy=False).__or__(np.array(other, copy=False))
80-
81-
def __ior__(self, other):
82-
return np.array(self, copy=False) | np.array(other, copy=False)
83-
84-
def __and__(self, other):
85-
return np.array(self, copy=False).__and__(np.array(other, copy=False))
86-
87-
def __iand__(self, other):
88-
return np.array(self, copy=False) & (np.array(other, copy=False))
89-
90-
@property
91-
def nbytes(self):
92-
return self._data.nbytes
93-
94-
@property
95-
def size(self):
96-
# TODO: should this be an EA property?
97-
return len(self)
98-
99-
def reshape(self, shape, **kwargs):
100-
return np.array(self, copy=False).reshape(shape, **kwargs)
101-
102-
def astype(self, dtype, copy=False):
103-
return np.array(self, copy=False).astype(dtype, copy=copy)
104-
105-
def any(self):
106-
return self._data.any()
107-
108-
def all(self):
109-
return self._data.all()
110-
111-
def copy(self):
112-
return type(self)(self._data.copy())
113-
114-
def sum(self, axis=None):
115-
return np.array(self, copy=False).sum()
116-
117-
def take(self, indicies, **kwargs):
118-
return np.array(self, copy=False).take(indicies)
119-
120-
12123
def get_mask_array_type():
12224
# TODO: protect imports
12325

12426
# if ArrowBoolArray is available use it
12527
# otherwise use the NumpyMask
12628
try:
127-
from pandas.core.arrays.bool import ArrowBoolArray
29+
from pandas.core.arrays._pyarrow_bool import ArrowBoolArray
12830

12931
class MaskArray(_MaskArray, ArrowBoolArray):
13032
pass
13133

13234
except (ModuleNotFoundError, ImportError):
35+
from pandas.core.arrays._numpy_bool import NumpyBoolArray
36+
13337
class MaskArray(_MaskArray, NumpyBoolArray):
13438
pass
13539

pandas/core/arrays/_numpy_bool.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""
2+
This module provide a numpy-boolean boolean array
3+
"""
4+
5+
import numpy as np
6+
from pandas.core.arrays import ExtensionArray
7+
8+
9+
class NumpyBoolArray(ExtensionArray):
10+
"""Generic class which can be used to represent missing data.
11+
"""
12+
13+
@property
14+
def dtype(self):
15+
return np.dtype('bool')
16+
17+
@classmethod
18+
def _from_sequence(cls, scalars, dtype=None, copy=False):
19+
arr = np.asarray(scalars).astype(np.bool_, copy=False)
20+
return cls(arr, copy=copy)
21+
22+
def __init__(self, mask, copy=True):
23+
"""
24+
Parameters
25+
----------
26+
mask : numpy array
27+
Mask of missing values.
28+
"""
29+
assert isinstance(mask, np.ndarray)
30+
assert mask.dtype == np.bool_
31+
32+
if copy:
33+
mask = mask.copy()
34+
self._data = mask
35+
36+
def __getitem__(self, key):
37+
return self._data[key]
38+
39+
def __setitem__(self, key, value):
40+
self._data[key] = value
41+
42+
def __len__(self):
43+
return len(self._data)
44+
45+
def __eq__(self, other):
46+
return np.array(self, copy=False) == np.array(other, copy=False)
47+
48+
def __array__(self, dtype=None):
49+
return self._data
50+
51+
def __iter__(self):
52+
return iter(self._data)
53+
54+
def __invert__(self):
55+
return type(self)(~self._data)
56+
57+
def __or__(self, other):
58+
return np.array(
59+
self, copy=False).__or__(np.array(other, copy=False))
60+
61+
def __ior__(self, other):
62+
return np.array(self, copy=False) | np.array(other, copy=False)
63+
64+
def __and__(self, other):
65+
return np.array(self, copy=False).__and__(np.array(other, copy=False))
66+
67+
def __iand__(self, other):
68+
return np.array(self, copy=False) & (np.array(other, copy=False))
69+
70+
@property
71+
def nbytes(self):
72+
return self._data.nbytes
73+
74+
@property
75+
def size(self):
76+
# TODO: should this be an EA property?
77+
return len(self)
78+
79+
def reshape(self, shape, **kwargs):
80+
return np.array(self, copy=False).reshape(shape, **kwargs)
81+
82+
def astype(self, dtype, copy=False):
83+
return np.array(self, copy=False).astype(dtype, copy=copy)
84+
85+
def any(self):
86+
return self._data.any()
87+
88+
def all(self):
89+
return self._data.all()
90+
91+
def copy(self):
92+
return type(self)(self._data.copy())
93+
94+
def sum(self, axis=None):
95+
return np.array(self, copy=False).sum()
96+
97+
def take(self, indicies, **kwargs):
98+
return np.array(self, copy=False).take(indicies)
File renamed without changes.

pandas/tests/arrays/test_mask.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,19 @@
33
import pytest
44
from pandas.util import testing as tm
55

6-
from pandas.core.arrays._mask import NumpyBoolArray
76

8-
9-
@pytest.fixture
10-
def numpy_data():
11-
return NumpyBoolArray([1, 0, 1])
12-
13-
14-
@pytest.fixture
15-
def arrow_data():
16-
pytest.importorskip('pyarrow', minversion="0.10.0")
17-
from pandas.core.arrays.bool import ArrowBoolArray
18-
return ArrowBoolArray([1, 0, 1])
19-
20-
21-
@pytest.fixture(params=['numpy', 'arrow'])
7+
@pytest.fixture(params=['numpy', 'arrow', 'mask'])
228
def mask_type(request):
239
if request.param == 'numpy':
10+
from pandas.core.arrays._numpy_bool import NumpyBoolArray
2411
return NumpyBoolArray
2512
elif request.param == 'arrow':
2613
pytest.importorskip('pyarrow', minversion="0.10.0")
27-
from pandas.core.arrays.bool import ArrowBoolArray
14+
from pandas.core.arrays._pyarrow_bool import ArrowBoolArray
2815
return ArrowBoolArray
16+
elif request.param == 'mask':
17+
from pandas.core.arrays._mask import get_mask_array_type
18+
return get_mask_array_type()
2919

3020

3121
@pytest.fixture

pandas/tests/arrays/test_bool.py renamed to pandas/tests/arrays/test_pyarrow_bool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
pytest.importorskip('pyarrow', minversion="0.10.0")
99

10-
from pandas.core.arrays.bool import (
10+
from pandas.core.arrays._pyarrow_bool import (
1111
ArrowBoolArray, ArrowBoolDtype) # isort:skip
1212

1313

0 commit comments

Comments
 (0)