Skip to content

Commit 7c9adf3

Browse files
jbrockmendelpull[bot]
authored andcommitted
De-privatize imported names (#36156)
1 parent 7617ac2 commit 7c9adf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+101
-101
lines changed

pandas/_libs/hashtable.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ from pandas._libs.missing cimport checknull
5656

5757

5858
cdef int64_t NPY_NAT = util.get_nat()
59-
_SIZE_HINT_LIMIT = (1 << 20) + 7
59+
SIZE_HINT_LIMIT = (1 << 20) + 7
6060

6161

6262
cdef Py_ssize_t _INIT_VEC_CAP = 128
@@ -176,7 +176,7 @@ def unique_label_indices(const int64_t[:] labels):
176176
ndarray[int64_t, ndim=1] arr
177177
Int64VectorData *ud = idx.data
178178

179-
kh_resize_int64(table, min(n, _SIZE_HINT_LIMIT))
179+
kh_resize_int64(table, min(n, SIZE_HINT_LIMIT))
180180

181181
with nogil:
182182
for i in range(n):

pandas/_libs/hashtable_class_helper.pxi.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ cdef class {{name}}HashTable(HashTable):
268268
def __cinit__(self, int64_t size_hint=1):
269269
self.table = kh_init_{{dtype}}()
270270
if size_hint is not None:
271-
size_hint = min(size_hint, _SIZE_HINT_LIMIT)
271+
size_hint = min(size_hint, SIZE_HINT_LIMIT)
272272
kh_resize_{{dtype}}(self.table, size_hint)
273273

274274
def __len__(self) -> int:
@@ -603,7 +603,7 @@ cdef class StringHashTable(HashTable):
603603
def __init__(self, int64_t size_hint=1):
604604
self.table = kh_init_str()
605605
if size_hint is not None:
606-
size_hint = min(size_hint, _SIZE_HINT_LIMIT)
606+
size_hint = min(size_hint, SIZE_HINT_LIMIT)
607607
kh_resize_str(self.table, size_hint)
608608

609609
def __dealloc__(self):
@@ -916,7 +916,7 @@ cdef class PyObjectHashTable(HashTable):
916916
def __init__(self, int64_t size_hint=1):
917917
self.table = kh_init_pymap()
918918
if size_hint is not None:
919-
size_hint = min(size_hint, _SIZE_HINT_LIMIT)
919+
size_hint = min(size_hint, SIZE_HINT_LIMIT)
920920
kh_resize_pymap(self.table, size_hint)
921921

922922
def __dealloc__(self):

pandas/_libs/hashtable_func_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def duplicated_{{dtype}}(const {{c_type}}[:] values, object keep='first'):
138138
kh_{{ttype}}_t *table = kh_init_{{ttype}}()
139139
ndarray[uint8_t, ndim=1, cast=True] out = np.empty(n, dtype='bool')
140140

141-
kh_resize_{{ttype}}(table, min(n, _SIZE_HINT_LIMIT))
141+
kh_resize_{{ttype}}(table, min(n, SIZE_HINT_LIMIT))
142142

143143
if keep not in ('last', 'first', False):
144144
raise ValueError('keep must be either "first", "last" or False')

pandas/_libs/parsers.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ from pandas._libs.khash cimport (
6767
khiter_t,
6868
)
6969

70-
from pandas.compat import _get_lzma_file, _import_lzma
70+
from pandas.compat import get_lzma_file, import_lzma
7171
from pandas.errors import DtypeWarning, EmptyDataError, ParserError, ParserWarning
7272

7373
from pandas.core.dtypes.common import (
@@ -82,7 +82,7 @@ from pandas.core.dtypes.common import (
8282
)
8383
from pandas.core.dtypes.concat import union_categoricals
8484

85-
lzma = _import_lzma()
85+
lzma = import_lzma()
8686

8787
cdef:
8888
float64_t INF = <float64_t>np.inf
@@ -638,9 +638,9 @@ cdef class TextReader:
638638
f'zip file {zip_names}')
639639
elif self.compression == 'xz':
640640
if isinstance(source, str):
641-
source = _get_lzma_file(lzma)(source, 'rb')
641+
source = get_lzma_file(lzma)(source, 'rb')
642642
else:
643-
source = _get_lzma_file(lzma)(filename=source)
643+
source = get_lzma_file(lzma)(filename=source)
644644
else:
645645
raise ValueError(f'Unrecognized compression type: '
646646
f'{self.compression}')

pandas/_testing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pandas._libs.lib import no_default
2626
import pandas._libs.testing as _testing
2727
from pandas._typing import Dtype, FilePathOrBuffer, FrameOrSeries
28-
from pandas.compat import _get_lzma_file, _import_lzma
28+
from pandas.compat import get_lzma_file, import_lzma
2929

3030
from pandas.core.dtypes.common import (
3131
is_bool,
@@ -70,7 +70,7 @@
7070
from pandas.io.common import urlopen
7171
from pandas.io.formats.printing import pprint_thing
7272

73-
lzma = _import_lzma()
73+
lzma = import_lzma()
7474

7575
_N = 30
7676
_K = 4
@@ -243,7 +243,7 @@ def decompress_file(path, compression):
243243
elif compression == "bz2":
244244
f = bz2.BZ2File(path, "rb")
245245
elif compression == "xz":
246-
f = _get_lzma_file(lzma)(path, "rb")
246+
f = get_lzma_file(lzma)(path, "rb")
247247
elif compression == "zip":
248248
zip_file = zipfile.ZipFile(path)
249249
zip_names = zip_file.namelist()
@@ -288,7 +288,7 @@ def write_to_compressed(compression, path, data, dest="test"):
288288
elif compression == "bz2":
289289
compress_method = bz2.BZ2File
290290
elif compression == "xz":
291-
compress_method = _get_lzma_file(lzma)
291+
compress_method = get_lzma_file(lzma)
292292
else:
293293
raise ValueError(f"Unrecognized compression type: {compression}")
294294

pandas/compat/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def is_platform_mac() -> bool:
7777
return sys.platform == "darwin"
7878

7979

80-
def _import_lzma():
80+
def import_lzma():
8181
"""
8282
Importing the `lzma` module.
8383
@@ -97,7 +97,7 @@ def _import_lzma():
9797
warnings.warn(msg)
9898

9999

100-
def _get_lzma_file(lzma):
100+
def get_lzma_file(lzma):
101101
"""
102102
Importing the `LZMAFile` class from the `lzma` module.
103103

pandas/core/algorithms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray:
462462
return f(comps, values)
463463

464464

465-
def _factorize_array(
465+
def factorize_array(
466466
values, na_sentinel: int = -1, size_hint=None, na_value=None, mask=None
467467
) -> Tuple[np.ndarray, np.ndarray]:
468468
"""
@@ -671,7 +671,7 @@ def factorize(
671671
else:
672672
na_value = None
673673

674-
codes, uniques = _factorize_array(
674+
codes, uniques = factorize_array(
675675
values, na_sentinel=na_sentinel, size_hint=size_hint, na_value=na_value
676676
)
677677

pandas/core/arrays/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from pandas.core.dtypes.missing import isna
3232

3333
from pandas.core import ops
34-
from pandas.core.algorithms import _factorize_array, unique
34+
from pandas.core.algorithms import factorize_array, unique
3535
from pandas.core.missing import backfill_1d, pad_1d
3636
from pandas.core.sorting import nargminmax, nargsort
3737

@@ -845,7 +845,7 @@ def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, "ExtensionArray"
845845
# Complete control over factorization.
846846
arr, na_value = self._values_for_factorize()
847847

848-
codes, uniques = _factorize_array(
848+
codes, uniques = factorize_array(
849849
arr, na_sentinel=na_sentinel, na_value=na_value
850850
)
851851

pandas/core/arrays/masked.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pandas.core.dtypes.missing import isna, notna
1818

1919
from pandas.core import nanops
20-
from pandas.core.algorithms import _factorize_array, take
20+
from pandas.core.algorithms import factorize_array, take
2121
from pandas.core.array_algos import masked_reductions
2222
from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
2323
from pandas.core.indexers import check_array_indexer
@@ -287,7 +287,7 @@ def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, ExtensionArray]:
287287
arr = self._data
288288
mask = self._mask
289289

290-
codes, uniques = _factorize_array(arr, na_sentinel=na_sentinel, mask=mask)
290+
codes, uniques = factorize_array(arr, na_sentinel=na_sentinel, mask=mask)
291291

292292
# the hashtables don't handle all different types of bits
293293
uniques = uniques.astype(self.dtype.numpy_dtype, copy=False)

pandas/core/computation/check.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from pandas.compat._optional import import_optional_dependency
22

33
ne = import_optional_dependency("numexpr", raise_on_missing=False, on_version="warn")
4-
_NUMEXPR_INSTALLED = ne is not None
5-
if _NUMEXPR_INSTALLED:
6-
_NUMEXPR_VERSION = ne.__version__
4+
NUMEXPR_INSTALLED = ne is not None
5+
if NUMEXPR_INSTALLED:
6+
NUMEXPR_VERSION = ne.__version__
77
else:
8-
_NUMEXPR_VERSION = None
8+
NUMEXPR_VERSION = None
99

10-
__all__ = ["_NUMEXPR_INSTALLED", "_NUMEXPR_VERSION"]
10+
__all__ = ["NUMEXPR_INSTALLED", "NUMEXPR_VERSION"]

pandas/core/computation/eval.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def _check_engine(engine: Optional[str]) -> str:
3838
str
3939
Engine name.
4040
"""
41-
from pandas.core.computation.check import _NUMEXPR_INSTALLED
41+
from pandas.core.computation.check import NUMEXPR_INSTALLED
4242

4343
if engine is None:
44-
engine = "numexpr" if _NUMEXPR_INSTALLED else "python"
44+
engine = "numexpr" if NUMEXPR_INSTALLED else "python"
4545

4646
if engine not in _engines:
4747
valid_engines = list(_engines.keys())
@@ -53,7 +53,7 @@ def _check_engine(engine: Optional[str]) -> str:
5353
# that won't necessarily be import-able)
5454
# Could potentially be done on engine instantiation
5555
if engine == "numexpr":
56-
if not _NUMEXPR_INSTALLED:
56+
if not NUMEXPR_INSTALLED:
5757
raise ImportError(
5858
"'numexpr' is not installed or an unsupported version. Cannot use "
5959
"engine='numexpr' for query/eval if 'numexpr' is not installed"

pandas/core/computation/expressions.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
from pandas.core.dtypes.generic import ABCDataFrame
1717

18-
from pandas.core.computation.check import _NUMEXPR_INSTALLED
18+
from pandas.core.computation.check import NUMEXPR_INSTALLED
1919
from pandas.core.ops import roperator
2020

21-
if _NUMEXPR_INSTALLED:
21+
if NUMEXPR_INSTALLED:
2222
import numexpr as ne
2323

2424
_TEST_MODE = None
2525
_TEST_RESULT: List[bool] = list()
26-
_USE_NUMEXPR = _NUMEXPR_INSTALLED
26+
_USE_NUMEXPR = NUMEXPR_INSTALLED
2727
_evaluate = None
2828
_where = None
2929

@@ -40,7 +40,7 @@
4040
def set_use_numexpr(v=True):
4141
# set/unset to use numexpr
4242
global _USE_NUMEXPR
43-
if _NUMEXPR_INSTALLED:
43+
if NUMEXPR_INSTALLED:
4444
_USE_NUMEXPR = v
4545

4646
# choose what we are going to do
@@ -53,7 +53,7 @@ def set_use_numexpr(v=True):
5353
def set_numexpr_threads(n=None):
5454
# if we are using numexpr, set the threads to n
5555
# otherwise reset
56-
if _NUMEXPR_INSTALLED and _USE_NUMEXPR:
56+
if NUMEXPR_INSTALLED and _USE_NUMEXPR:
5757
if n is None:
5858
n = ne.detect_number_of_cores()
5959
ne.set_num_threads(n)

pandas/core/computation/ops.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,11 @@ def __repr__(self) -> str:
600600

601601
class FuncNode:
602602
def __init__(self, name: str):
603-
from pandas.core.computation.check import _NUMEXPR_INSTALLED, _NUMEXPR_VERSION
603+
from pandas.core.computation.check import NUMEXPR_INSTALLED, NUMEXPR_VERSION
604604

605605
if name not in _mathops or (
606-
_NUMEXPR_INSTALLED
607-
and _NUMEXPR_VERSION < LooseVersion("2.6.9")
606+
NUMEXPR_INSTALLED
607+
and NUMEXPR_VERSION < LooseVersion("2.6.9")
608608
and name in ("floor", "ceil")
609609
):
610610
raise ValueError(f'"{name}" is not a supported function')

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5257,7 +5257,7 @@ def duplicated(
52575257
4 True
52585258
dtype: bool
52595259
"""
5260-
from pandas._libs.hashtable import _SIZE_HINT_LIMIT, duplicated_int64
5260+
from pandas._libs.hashtable import SIZE_HINT_LIMIT, duplicated_int64
52615261

52625262
from pandas.core.sorting import get_group_index
52635263

@@ -5266,7 +5266,7 @@ def duplicated(
52665266

52675267
def f(vals):
52685268
labels, shape = algorithms.factorize(
5269-
vals, size_hint=min(len(self), _SIZE_HINT_LIMIT)
5269+
vals, size_hint=min(len(self), SIZE_HINT_LIMIT)
52705270
)
52715271
return labels.astype("i8", copy=False), len(shape)
52725272

pandas/core/indexes/multi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,9 @@ def format(
13421342
)
13431343

13441344
if adjoin:
1345-
from pandas.io.formats.format import _get_adjustment
1345+
from pandas.io.formats.format import get_adjustment
13461346

1347-
adj = _get_adjustment()
1347+
adj = get_adjustment()
13481348
return adj.adjoin(space, *result_levels).split("\n")
13491349
else:
13501350
return result_levels

pandas/core/internals/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
IntBlock,
1111
ObjectBlock,
1212
TimeDeltaBlock,
13-
_safe_reshape,
1413
make_block,
14+
safe_reshape,
1515
)
1616
from pandas.core.internals.concat import concatenate_block_managers
1717
from pandas.core.internals.managers import (
@@ -33,7 +33,7 @@
3333
"IntBlock",
3434
"ObjectBlock",
3535
"TimeDeltaBlock",
36-
"_safe_reshape",
36+
"safe_reshape",
3737
"make_block",
3838
"BlockManager",
3939
"SingleBlockManager",

pandas/core/internals/blocks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ def putmask(
16781678
if isinstance(new, (np.ndarray, ExtensionArray)) and len(new) == len(mask):
16791679
new = new[mask]
16801680

1681-
mask = _safe_reshape(mask, new_values.shape)
1681+
mask = safe_reshape(mask, new_values.shape)
16821682

16831683
new_values[mask] = new
16841684
return [self.make_block(values=new_values)]
@@ -2820,7 +2820,7 @@ def _block_shape(values: ArrayLike, ndim: int = 1) -> ArrayLike:
28202820
return values
28212821

28222822

2823-
def _safe_reshape(arr, new_shape):
2823+
def safe_reshape(arr, new_shape):
28242824
"""
28252825
If possible, reshape `arr` to have shape `new_shape`,
28262826
with a couple of exceptions (see gh-13012):

pandas/core/internals/managers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
DatetimeTZBlock,
4848
ExtensionBlock,
4949
ObjectValuesExtensionBlock,
50-
_safe_reshape,
5150
extend_blocks,
5251
get_block_type,
5352
make_block,
53+
safe_reshape,
5454
)
5555
from pandas.core.internals.ops import blockwise_all, operate_blockwise
5656

@@ -1015,7 +1015,7 @@ def value_getitem(placement):
10151015

10161016
else:
10171017
if value.ndim == self.ndim - 1:
1018-
value = _safe_reshape(value, (1,) + value.shape)
1018+
value = safe_reshape(value, (1,) + value.shape)
10191019

10201020
def value_getitem(placement):
10211021
return value
@@ -1138,7 +1138,7 @@ def insert(self, loc: int, item: Label, value, allow_duplicates: bool = False):
11381138

11391139
if value.ndim == self.ndim - 1 and not is_extension_array_dtype(value.dtype):
11401140
# TODO(EA2D): special case not needed with 2D EAs
1141-
value = _safe_reshape(value, (1,) + value.shape)
1141+
value = safe_reshape(value, (1,) + value.shape)
11421142

11431143
block = make_block(values=value, ndim=self.ndim, placement=slice(loc, loc + 1))
11441144

pandas/core/sorting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def compress_group_index(group_index, sort: bool = True):
520520
space can be huge, so this function compresses it, by computing offsets
521521
(comp_ids) into the list of unique labels (obs_group_ids).
522522
"""
523-
size_hint = min(len(group_index), hashtable._SIZE_HINT_LIMIT)
523+
size_hint = min(len(group_index), hashtable.SIZE_HINT_LIMIT)
524524
table = hashtable.Int64HashTable(size_hint)
525525

526526
group_index = ensure_int64(group_index)

0 commit comments

Comments
 (0)