Skip to content

Commit 0f3276e

Browse files
committed
better get_mask_array_type
1 parent 9fe46d4 commit 0f3276e

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pandas/core/arrays/_mask.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""A boolean mask interace.
22
33
This module provides an interface to a numpy / pyarrow boolean mask.
4+
This is limited as not all of the implementations can hold NA, so
5+
for consistency this is an internal.
46
"""
57

8+
_MaskArrayType = None
9+
610

711
class _MaskArray:
812
_typ = "maskarray"
@@ -21,7 +25,14 @@ def _reduce(self, method, skipna=True, **kwargs):
2125

2226

2327
def get_mask_array_type():
24-
# TODO: protect imports
28+
"""Set the mask array type to use, we need to do
29+
this after all modules are imported as the implementations
30+
e.g. pyarrow depend on pandas being importable
31+
"""
32+
global _MaskArrayType
33+
34+
if _MaskArrayType is not None:
35+
return _MaskArrayType
2536

2637
# if ArrowBoolArray is available use it
2738
# otherwise use the NumpyMask
@@ -37,4 +48,5 @@ class MaskArray(_MaskArray, ArrowBoolArray):
3748
class MaskArray(_MaskArray, NumpyBoolArray):
3849
pass
3950

40-
return MaskArray
51+
_MaskArrayType = MaskArray
52+
return _MaskArrayType

pandas/core/arrays/_numpy_bool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import numpy as np
6+
67
from pandas.core.arrays import ExtensionArray
78

89

pandas/tests/dtypes/test_common.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,6 @@ def test_is_bool_dtype():
527527
assert com.is_bool_dtype(np.bool)
528528
assert com.is_bool_dtype(np.array([True, False]))
529529
assert com.is_bool_dtype(pd.Index([True, False]))
530-
531-
# TODO: hack-a-minute
532530
assert com.is_bool_dtype(
533531
get_mask_array_type()._from_sequence([True, False]))
534532

0 commit comments

Comments
 (0)