Skip to content

Commit d26f99a

Browse files
authored
STY: de-privatize names imported across modules (#36178)
1 parent 490a999 commit d26f99a

36 files changed

+135
-133
lines changed

pandas/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
# numpy compat
2222
from pandas.compat.numpy import (
23-
_np_version_under1p17,
24-
_np_version_under1p18,
25-
_is_numpy_dev,
23+
np_version_under1p17 as _np_version_under1p17,
24+
np_version_under1p18 as _np_version_under1p18,
25+
is_numpy_dev as _is_numpy_dev,
2626
)
2727

2828
try:

pandas/_testing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ def use_numexpr(use, min_elements=None):
27132713
if min_elements is None:
27142714
min_elements = expr._MIN_ELEMENTS
27152715

2716-
olduse = expr._USE_NUMEXPR
2716+
olduse = expr.USE_NUMEXPR
27172717
oldmin = expr._MIN_ELEMENTS
27182718
expr.set_use_numexpr(use)
27192719
expr._MIN_ELEMENTS = min_elements

pandas/compat/numpy/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# numpy versioning
99
_np_version = np.__version__
1010
_nlv = LooseVersion(_np_version)
11-
_np_version_under1p17 = _nlv < LooseVersion("1.17")
12-
_np_version_under1p18 = _nlv < LooseVersion("1.18")
11+
np_version_under1p17 = _nlv < LooseVersion("1.17")
12+
np_version_under1p18 = _nlv < LooseVersion("1.18")
1313
_np_version_under1p19 = _nlv < LooseVersion("1.19")
1414
_np_version_under1p20 = _nlv < LooseVersion("1.20")
15-
_is_numpy_dev = ".dev" in str(_nlv)
15+
is_numpy_dev = ".dev" in str(_nlv)
1616
_min_numpy_ver = "1.16.5"
1717

1818

@@ -65,6 +65,6 @@ def np_array_datetime64_compat(arr, *args, **kwargs):
6565
__all__ = [
6666
"np",
6767
"_np_version",
68-
"_np_version_under1p17",
69-
"_is_numpy_dev",
68+
"np_version_under1p17",
69+
"is_numpy_dev",
7070
]

pandas/core/array_algos/masked_reductions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99

1010
from pandas._libs import missing as libmissing
11-
from pandas.compat.numpy import _np_version_under1p17
11+
from pandas.compat.numpy import np_version_under1p17
1212

1313
from pandas.core.nanops import check_below_min_count
1414

@@ -46,7 +46,7 @@ def _sumprod(
4646
if check_below_min_count(values.shape, mask, min_count):
4747
return libmissing.NA
4848

49-
if _np_version_under1p17:
49+
if np_version_under1p17:
5050
return func(values[~mask])
5151
else:
5252
return func(values, where=~mask)

pandas/core/arrays/sparse/accessor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ def from_coo(cls, A, dense_index=False):
8888
dtype: Sparse[float64, nan]
8989
"""
9090
from pandas import Series
91-
from pandas.core.arrays.sparse.scipy_sparse import _coo_to_sparse_series
91+
from pandas.core.arrays.sparse.scipy_sparse import coo_to_sparse_series
9292

93-
result = _coo_to_sparse_series(A, dense_index=dense_index)
93+
result = coo_to_sparse_series(A, dense_index=dense_index)
9494
result = Series(result.array, index=result.index, copy=False)
9595

9696
return result
@@ -168,9 +168,9 @@ def to_coo(self, row_levels=(0,), column_levels=(1,), sort_labels=False):
168168
>>> columns
169169
[('a', 0), ('a', 1), ('b', 0), ('b', 1)]
170170
"""
171-
from pandas.core.arrays.sparse.scipy_sparse import _sparse_series_to_coo
171+
from pandas.core.arrays.sparse.scipy_sparse import sparse_series_to_coo
172172

173-
A, rows, columns = _sparse_series_to_coo(
173+
A, rows, columns = sparse_series_to_coo(
174174
self._parent, row_levels, column_levels, sort_labels=sort_labels
175175
)
176176
return A, rows, columns

pandas/core/arrays/sparse/scipy_sparse.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _get_index_subset_to_coord_dict(index, subset, sort_labels=False):
8585
return values, i_coord, j_coord, i_labels, j_labels
8686

8787

88-
def _sparse_series_to_coo(ss, row_levels=(0,), column_levels=(1,), sort_labels=False):
88+
def sparse_series_to_coo(ss, row_levels=(0,), column_levels=(1,), sort_labels=False):
8989
"""
9090
Convert a sparse Series to a scipy.sparse.coo_matrix using index
9191
levels row_levels, column_levels as the row and column
@@ -113,7 +113,7 @@ def _sparse_series_to_coo(ss, row_levels=(0,), column_levels=(1,), sort_labels=F
113113
return sparse_matrix, rows, columns
114114

115115

116-
def _coo_to_sparse_series(A, dense_index: bool = False):
116+
def coo_to_sparse_series(A, dense_index: bool = False):
117117
"""
118118
Convert a scipy.sparse.coo_matrix to a SparseSeries.
119119

pandas/core/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from pandas._libs import lib, tslibs
1818
from pandas._typing import AnyArrayLike, Scalar, T
19-
from pandas.compat.numpy import _np_version_under1p18
19+
from pandas.compat.numpy import np_version_under1p18
2020

2121
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
2222
from pandas.core.dtypes.common import (
@@ -425,7 +425,7 @@ def random_state(state=None):
425425
if (
426426
is_integer(state)
427427
or is_array_like(state)
428-
or (not _np_version_under1p18 and isinstance(state, np.random.BitGenerator))
428+
or (not np_version_under1p18 and isinstance(state, np.random.BitGenerator))
429429
):
430430
return np.random.RandomState(state)
431431
elif isinstance(state, np.random.RandomState):

pandas/core/computation/engines.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from typing import Dict, Type
77

88
from pandas.core.computation.align import align_terms, reconstruct_object
9-
from pandas.core.computation.ops import _mathops, _reductions
9+
from pandas.core.computation.ops import MATHOPS, REDUCTIONS
1010

1111
import pandas.io.formats.printing as printing
1212

13-
_ne_builtins = frozenset(_mathops + _reductions)
13+
_ne_builtins = frozenset(MATHOPS + REDUCTIONS)
1414

1515

1616
class NumExprClobberingError(NameError):

pandas/core/computation/expr.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212

1313
import pandas.core.common as com
1414
from pandas.core.computation.ops import (
15-
_LOCAL_TAG,
15+
ARITH_OPS_SYMS,
16+
BOOL_OPS_SYMS,
17+
CMP_OPS_SYMS,
18+
LOCAL_TAG,
19+
MATHOPS,
20+
REDUCTIONS,
21+
UNARY_OPS_SYMS,
1622
BinOp,
1723
Constant,
1824
Div,
@@ -21,12 +27,6 @@
2127
Term,
2228
UnaryOp,
2329
UndefinedVariableError,
24-
_arith_ops_syms,
25-
_bool_ops_syms,
26-
_cmp_ops_syms,
27-
_mathops,
28-
_reductions,
29-
_unary_ops_syms,
3030
is_term,
3131
)
3232
from pandas.core.computation.parsing import clean_backtick_quoted_toks, tokenize_string
@@ -101,7 +101,7 @@ def _replace_locals(tok: Tuple[int, str]) -> Tuple[int, str]:
101101
"""
102102
toknum, tokval = tok
103103
if toknum == tokenize.OP and tokval == "@":
104-
return tokenize.OP, _LOCAL_TAG
104+
return tokenize.OP, LOCAL_TAG
105105
return toknum, tokval
106106

107107

@@ -338,7 +338,7 @@ class BaseExprVisitor(ast.NodeVisitor):
338338
const_type: Type[Term] = Constant
339339
term_type = Term
340340

341-
binary_ops = _cmp_ops_syms + _bool_ops_syms + _arith_ops_syms
341+
binary_ops = CMP_OPS_SYMS + BOOL_OPS_SYMS + ARITH_OPS_SYMS
342342
binary_op_nodes = (
343343
"Gt",
344344
"Lt",
@@ -362,7 +362,7 @@ class BaseExprVisitor(ast.NodeVisitor):
362362
)
363363
binary_op_nodes_map = dict(zip(binary_ops, binary_op_nodes))
364364

365-
unary_ops = _unary_ops_syms
365+
unary_ops = UNARY_OPS_SYMS
366366
unary_op_nodes = "UAdd", "USub", "Invert", "Not"
367367
unary_op_nodes_map = {k: v for k, v in zip(unary_ops, unary_op_nodes)}
368368

@@ -494,7 +494,7 @@ def _maybe_evaluate_binop(
494494

495495
if self.engine != "pytables":
496496
if (
497-
res.op in _cmp_ops_syms
497+
res.op in CMP_OPS_SYMS
498498
and getattr(lhs, "is_datetime", False)
499499
or getattr(rhs, "is_datetime", False)
500500
):
@@ -726,7 +726,7 @@ def visitor(x, y):
726726

727727

728728
_python_not_supported = frozenset(["Dict", "BoolOp", "In", "NotIn"])
729-
_numexpr_supported_calls = frozenset(_reductions + _mathops)
729+
_numexpr_supported_calls = frozenset(REDUCTIONS + MATHOPS)
730730

731731

732732
@disallow(

pandas/core/computation/expressions.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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

@@ -39,21 +39,21 @@
3939

4040
def set_use_numexpr(v=True):
4141
# set/unset to use numexpr
42-
global _USE_NUMEXPR
42+
global USE_NUMEXPR
4343
if NUMEXPR_INSTALLED:
44-
_USE_NUMEXPR = v
44+
USE_NUMEXPR = v
4545

4646
# choose what we are going to do
4747
global _evaluate, _where
4848

49-
_evaluate = _evaluate_numexpr if _USE_NUMEXPR else _evaluate_standard
50-
_where = _where_numexpr if _USE_NUMEXPR else _where_standard
49+
_evaluate = _evaluate_numexpr if USE_NUMEXPR else _evaluate_standard
50+
_where = _where_numexpr if USE_NUMEXPR else _where_standard
5151

5252

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

+19-19
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import pandas.core.common as com
1818
from pandas.core.computation.common import ensure_decoded, result_type_many
19-
from pandas.core.computation.scope import _DEFAULT_GLOBALS
19+
from pandas.core.computation.scope import DEFAULT_GLOBALS
2020

2121
from pandas.io.formats.printing import pprint_thing, pprint_thing_encoded
2222

23-
_reductions = ("sum", "prod")
23+
REDUCTIONS = ("sum", "prod")
2424

2525
_unary_math_ops = (
2626
"sin",
@@ -46,10 +46,10 @@
4646
)
4747
_binary_math_ops = ("arctan2",)
4848

49-
_mathops = _unary_math_ops + _binary_math_ops
49+
MATHOPS = _unary_math_ops + _binary_math_ops
5050

5151

52-
_LOCAL_TAG = "__pd_eval_local_"
52+
LOCAL_TAG = "__pd_eval_local_"
5353

5454

5555
class UndefinedVariableError(NameError):
@@ -80,13 +80,13 @@ def __init__(self, name, env, side=None, encoding=None):
8080
self.env = env
8181
self.side = side
8282
tname = str(name)
83-
self.is_local = tname.startswith(_LOCAL_TAG) or tname in _DEFAULT_GLOBALS
83+
self.is_local = tname.startswith(LOCAL_TAG) or tname in DEFAULT_GLOBALS
8484
self._value = self._resolve_name()
8585
self.encoding = encoding
8686

8787
@property
8888
def local_name(self) -> str:
89-
return self.name.replace(_LOCAL_TAG, "")
89+
return self.name.replace(LOCAL_TAG, "")
9090

9191
def __repr__(self) -> str:
9292
return pprint_thing(self.name)
@@ -220,7 +220,7 @@ def __repr__(self) -> str:
220220
@property
221221
def return_type(self):
222222
# clobber types to bool if the op is a boolean operator
223-
if self.op in (_cmp_ops_syms + _bool_ops_syms):
223+
if self.op in (CMP_OPS_SYMS + BOOL_OPS_SYMS):
224224
return np.bool_
225225
return result_type_many(*(term.type for term in com.flatten(self)))
226226

@@ -280,7 +280,7 @@ def _not_in(x, y):
280280
return x not in y
281281

282282

283-
_cmp_ops_syms = (">", "<", ">=", "<=", "==", "!=", "in", "not in")
283+
CMP_OPS_SYMS = (">", "<", ">=", "<=", "==", "!=", "in", "not in")
284284
_cmp_ops_funcs = (
285285
operator.gt,
286286
operator.lt,
@@ -291,13 +291,13 @@ def _not_in(x, y):
291291
_in,
292292
_not_in,
293293
)
294-
_cmp_ops_dict = dict(zip(_cmp_ops_syms, _cmp_ops_funcs))
294+
_cmp_ops_dict = dict(zip(CMP_OPS_SYMS, _cmp_ops_funcs))
295295

296-
_bool_ops_syms = ("&", "|", "and", "or")
296+
BOOL_OPS_SYMS = ("&", "|", "and", "or")
297297
_bool_ops_funcs = (operator.and_, operator.or_, operator.and_, operator.or_)
298-
_bool_ops_dict = dict(zip(_bool_ops_syms, _bool_ops_funcs))
298+
_bool_ops_dict = dict(zip(BOOL_OPS_SYMS, _bool_ops_funcs))
299299

300-
_arith_ops_syms = ("+", "-", "*", "/", "**", "//", "%")
300+
ARITH_OPS_SYMS = ("+", "-", "*", "/", "**", "//", "%")
301301
_arith_ops_funcs = (
302302
operator.add,
303303
operator.sub,
@@ -307,12 +307,12 @@ def _not_in(x, y):
307307
operator.floordiv,
308308
operator.mod,
309309
)
310-
_arith_ops_dict = dict(zip(_arith_ops_syms, _arith_ops_funcs))
310+
_arith_ops_dict = dict(zip(ARITH_OPS_SYMS, _arith_ops_funcs))
311311

312-
_special_case_arith_ops_syms = ("**", "//", "%")
312+
SPECIAL_CASE_ARITH_OPS_SYMS = ("**", "//", "%")
313313
_special_case_arith_ops_funcs = (operator.pow, operator.floordiv, operator.mod)
314314
_special_case_arith_ops_dict = dict(
315-
zip(_special_case_arith_ops_syms, _special_case_arith_ops_funcs)
315+
zip(SPECIAL_CASE_ARITH_OPS_SYMS, _special_case_arith_ops_funcs)
316316
)
317317

318318
_binary_ops_dict = {}
@@ -530,9 +530,9 @@ def __init__(self, lhs, rhs):
530530
_cast_inplace(com.flatten(self), acceptable_dtypes, np.float_)
531531

532532

533-
_unary_ops_syms = ("+", "-", "~", "not")
533+
UNARY_OPS_SYMS = ("+", "-", "~", "not")
534534
_unary_ops_funcs = (operator.pos, operator.neg, operator.invert, operator.invert)
535-
_unary_ops_dict = dict(zip(_unary_ops_syms, _unary_ops_funcs))
535+
_unary_ops_dict = dict(zip(UNARY_OPS_SYMS, _unary_ops_funcs))
536536

537537

538538
class UnaryOp(Op):
@@ -561,7 +561,7 @@ def __init__(self, op: str, operand):
561561
except KeyError as err:
562562
raise ValueError(
563563
f"Invalid unary operator {repr(op)}, "
564-
f"valid operators are {_unary_ops_syms}"
564+
f"valid operators are {UNARY_OPS_SYMS}"
565565
) from err
566566

567567
def __call__(self, env):
@@ -602,7 +602,7 @@ class FuncNode:
602602
def __init__(self, name: str):
603603
from pandas.core.computation.check import NUMEXPR_INSTALLED, NUMEXPR_VERSION
604604

605-
if name not in _mathops or (
605+
if name not in MATHOPS or (
606606
NUMEXPR_INSTALLED
607607
and NUMEXPR_VERSION < LooseVersion("2.6.9")
608608
and name in ("floor", "ceil")

pandas/core/computation/scope.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _raw_hex_id(obj) -> str:
5353
return "".join(_replacer(x) for x in packed)
5454

5555

56-
_DEFAULT_GLOBALS = {
56+
DEFAULT_GLOBALS = {
5757
"Timestamp": Timestamp,
5858
"datetime": datetime.datetime,
5959
"True": True,
@@ -114,7 +114,7 @@ def __init__(
114114

115115
# shallow copy because we don't want to keep filling this up with what
116116
# was there before if there are multiple calls to Scope/_ensure_scope
117-
self.scope = DeepChainMap(_DEFAULT_GLOBALS.copy())
117+
self.scope = DeepChainMap(DEFAULT_GLOBALS.copy())
118118
self.target = target
119119

120120
if isinstance(local_dict, Scope):

0 commit comments

Comments
 (0)