Skip to content

Commit 6e28008

Browse files
authored
STY+CI: check for private function access across modules (#36144)
1 parent bdb6e26 commit 6e28008

File tree

14 files changed

+111
-33
lines changed

14 files changed

+111
-33
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ doc:
2525
cd doc; \
2626
python make.py clean; \
2727
python make.py html
28+
29+
check:
30+
python3 scripts/validate_unwanted_patterns.py \
31+
--validation-type="private_function_across_module" \
32+
--included-file-extensions="py" \
33+
--excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored \
34+
pandas/

ci/code_checks.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
116116
fi
117117
RET=$(($RET + $?)) ; echo $MSG "DONE"
118118

119+
MSG='Check for use of private module attribute access' ; echo $MSG
120+
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
121+
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored --format="##[error]{source_path}:{line_number}:{msg}" pandas/
122+
else
123+
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
124+
fi
125+
RET=$(($RET + $?)) ; echo $MSG "DONE"
126+
119127
echo "isort --version-number"
120128
isort --version-number
121129

pandas/_libs/algos.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ ctypedef fused algos_t:
412412
uint8_t
413413

414414

415-
def _validate_limit(nobs: int, limit=None) -> int:
415+
def validate_limit(nobs: int, limit=None) -> int:
416416
"""
417417
Check that the `limit` argument is a positive integer.
418418

@@ -452,7 +452,7 @@ def pad(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
452452
indexer = np.empty(nright, dtype=np.int64)
453453
indexer[:] = -1
454454

455-
lim = _validate_limit(nright, limit)
455+
lim = validate_limit(nright, limit)
456456

457457
if nleft == 0 or nright == 0 or new[nright - 1] < old[0]:
458458
return indexer
@@ -509,7 +509,7 @@ def pad_inplace(algos_t[:] values, const uint8_t[:] mask, limit=None):
509509
if N == 0:
510510
return
511511

512-
lim = _validate_limit(N, limit)
512+
lim = validate_limit(N, limit)
513513

514514
val = values[0]
515515
for i in range(N):
@@ -537,7 +537,7 @@ def pad_2d_inplace(algos_t[:, :] values, const uint8_t[:, :] mask, limit=None):
537537
if N == 0:
538538
return
539539

540-
lim = _validate_limit(N, limit)
540+
lim = validate_limit(N, limit)
541541

542542
for j in range(K):
543543
fill_count = 0
@@ -593,7 +593,7 @@ def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None) -> ndarray:
593593
indexer = np.empty(nright, dtype=np.int64)
594594
indexer[:] = -1
595595

596-
lim = _validate_limit(nright, limit)
596+
lim = validate_limit(nright, limit)
597597

598598
if nleft == 0 or nright == 0 or new[0] > old[nleft - 1]:
599599
return indexer
@@ -651,7 +651,7 @@ def backfill_inplace(algos_t[:] values, const uint8_t[:] mask, limit=None):
651651
if N == 0:
652652
return
653653

654-
lim = _validate_limit(N, limit)
654+
lim = validate_limit(N, limit)
655655

656656
val = values[N - 1]
657657
for i in range(N - 1, -1, -1):
@@ -681,7 +681,7 @@ def backfill_2d_inplace(algos_t[:, :] values,
681681
if N == 0:
682682
return
683683

684-
lim = _validate_limit(N, limit)
684+
lim = validate_limit(N, limit)
685685

686686
for j in range(K):
687687
fill_count = 0

pandas/core/algorithms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from pandas.core.indexers import validate_indices
6161

6262
if TYPE_CHECKING:
63-
from pandas import Categorical, DataFrame, Series
63+
from pandas import Categorical, DataFrame, Series # noqa:F401
6464

6565
_shared_docs: Dict[str, str] = {}
6666

@@ -767,7 +767,7 @@ def value_counts(
767767
counts = result._values
768768

769769
else:
770-
keys, counts = _value_counts_arraylike(values, dropna)
770+
keys, counts = value_counts_arraylike(values, dropna)
771771

772772
result = Series(counts, index=keys, name=name)
773773

@@ -780,8 +780,8 @@ def value_counts(
780780
return result
781781

782782

783-
# Called once from SparseArray
784-
def _value_counts_arraylike(values, dropna: bool):
783+
# Called once from SparseArray, otherwise could be private
784+
def value_counts_arraylike(values, dropna: bool):
785785
"""
786786
Parameters
787787
----------

pandas/core/arrays/sparse/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def value_counts(self, dropna=True):
735735
"""
736736
from pandas import Index, Series
737737

738-
keys, counts = algos._value_counts_arraylike(self.sp_values, dropna=dropna)
738+
keys, counts = algos.value_counts_arraylike(self.sp_values, dropna=dropna)
739739
fcounts = self.sp_index.ngaps
740740
if fcounts > 0:
741741
if self._null_fill_value and dropna:

pandas/core/internals/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def fillna(
390390

391391
mask = isna(self.values)
392392
if limit is not None:
393-
limit = libalgos._validate_limit(None, limit=limit)
393+
limit = libalgos.validate_limit(None, limit=limit)
394394
mask[mask.cumsum(self.ndim - 1) > limit] = False
395395

396396
if not self._can_hold_na:

pandas/core/missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def interpolate_1d(
228228
)
229229

230230
# default limit is unlimited GH #16282
231-
limit = algos._validate_limit(nobs=None, limit=limit)
231+
limit = algos.validate_limit(nobs=None, limit=limit)
232232

233233
# These are sets of index pointers to invalid values... i.e. {0, 1, etc...
234234
all_nans = set(np.flatnonzero(invalid))

pandas/plotting/_matplotlib/compat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def inner():
1717
return inner
1818

1919

20-
_mpl_ge_2_2_3 = _mpl_version("2.2.3", operator.ge)
21-
_mpl_ge_3_0_0 = _mpl_version("3.0.0", operator.ge)
22-
_mpl_ge_3_1_0 = _mpl_version("3.1.0", operator.ge)
23-
_mpl_ge_3_2_0 = _mpl_version("3.2.0", operator.ge)
24-
_mpl_ge_3_3_0 = _mpl_version("3.3.0", operator.ge)
20+
mpl_ge_2_2_3 = _mpl_version("2.2.3", operator.ge)
21+
mpl_ge_3_0_0 = _mpl_version("3.0.0", operator.ge)
22+
mpl_ge_3_1_0 = _mpl_version("3.1.0", operator.ge)
23+
mpl_ge_3_2_0 = _mpl_version("3.2.0", operator.ge)
24+
mpl_ge_3_3_0 = _mpl_version("3.3.0", operator.ge)

pandas/plotting/_matplotlib/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import pandas.core.common as com
3030

3131
from pandas.io.formats.printing import pprint_thing
32-
from pandas.plotting._matplotlib.compat import _mpl_ge_3_0_0
32+
from pandas.plotting._matplotlib.compat import mpl_ge_3_0_0
3333
from pandas.plotting._matplotlib.converter import register_pandas_matplotlib_converters
3434
from pandas.plotting._matplotlib.style import get_standard_colors
3535
from pandas.plotting._matplotlib.timeseries import (
@@ -944,7 +944,7 @@ def _plot_colorbar(self, ax: "Axes", **kwds):
944944
img = ax.collections[-1]
945945
cbar = self.fig.colorbar(img, ax=ax, **kwds)
946946

947-
if _mpl_ge_3_0_0():
947+
if mpl_ge_3_0_0():
948948
# The workaround below is no longer necessary.
949949
return
950950

pandas/plotting/_matplotlib/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def handle_shared_axes(
307307
sharey: bool,
308308
):
309309
if nplots > 1:
310-
if compat._mpl_ge_3_2_0():
310+
if compat.mpl_ge_3_2_0():
311311
row_num = lambda x: x.get_subplotspec().rowspan.start
312312
col_num = lambda x: x.get_subplotspec().colspan.start
313313
else:

0 commit comments

Comments
 (0)