Skip to content

Commit ed18b43

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into sty-private
2 parents 7ab6598 + 42289d0 commit ed18b43

33 files changed

+241
-222
lines changed

Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ doc:
2828

2929
check:
3030
python3 scripts/validate_unwanted_patterns.py \
31-
--validation-type="private_import_across_module" \
32-
--included-file-extensions="py" pandas/ \
33-
--excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored
31+
--validation-type="private_function_across_module" \
32+
--included-file-extensions="py" \
33+
--excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored \
34+
pandas/
3435

3536
python3 scripts/validate_unwanted_patterns.py \
36-
--validation-type="private_function_across_module" \
37-
--included-file-extensions="py" pandas/ \
38-
--excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored
37+
--validation-type="private_import_across_module" \
38+
--included-file-extensions="py" \
39+
--excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored \
40+
pandas/

ci/code_checks.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,18 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
116116
fi
117117
RET=$(($RET + $?)) ; echo $MSG "DONE"
118118

119-
MSG='Check for use of private functions across modules' ; echo $MSG
119+
MSG='Check for use of private import across modules' ; echo $MSG
120120
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
121-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module" --included-file-extensions="py" --format="##[error]{source_path}:{line_number}:{msg}" pandas/
121+
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module" --included-file-extensions="py" --format="##[error]{source_path}:{line_number}:{msg}" pandas/
122122
else
123-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module" --included-file-extensions="py" pandas/
123+
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module" --included-file-extensions="py" pandas/
124+
RET=$(($RET + $?)) ; echo $MSG "DONE"
125+
126+
MSG='Check for use of private module attribute access' ; echo $MSG
127+
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
128+
$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/
129+
else
130+
$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/
124131
fi
125132
RET=$(($RET + $?)) ; echo $MSG "DONE"
126133

@@ -238,6 +245,9 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
238245
invgrep -R --include=*.{py,pyx} '!r}' pandas
239246
RET=$(($RET + $?)) ; echo $MSG "DONE"
240247

248+
# -------------------------------------------------------------------------
249+
# Type annotations
250+
241251
MSG='Check for use of comment-based annotation syntax' ; echo $MSG
242252
invgrep -R --include="*.py" -P '# type: (?!ignore)' pandas
243253
RET=$(($RET + $?)) ; echo $MSG "DONE"
@@ -246,6 +256,11 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
246256
invgrep -R --include="*.py" -P '# type:\s?ignore(?!\[)' pandas
247257
RET=$(($RET + $?)) ; echo $MSG "DONE"
248258

259+
MSG='Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias' ; echo $MSG
260+
invgrep -R --include="*.py" --exclude=_typing.py -E 'Union\[.*(Series.*DataFrame|DataFrame.*Series).*\]' pandas
261+
RET=$(($RET + $?)) ; echo $MSG "DONE"
262+
263+
# -------------------------------------------------------------------------
249264
MSG='Check for use of foo.__class__ instead of type(foo)' ; echo $MSG
250265
invgrep -R --include=*.{py,pyx} '\.__class__' pandas
251266
RET=$(($RET + $?)) ; echo $MSG "DONE"

doc/source/whatsnew/v1.2.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,12 @@ I/O
295295
- :meth:`to_csv` passes compression arguments for `'gzip'` always to `gzip.GzipFile` (:issue:`28103`)
296296
- :meth:`to_csv` did not support zip compression for binary file object not having a filename (:issue: `35058`)
297297
- :meth:`to_csv` and :meth:`read_csv` did not honor `compression` and `encoding` for path-like objects that are internally converted to file-like objects (:issue:`35677`, :issue:`26124`, and :issue:`32392`)
298+
- :meth:`to_picke` and :meth:`read_pickle` did not support compression for file-objects (:issue:`26237`, :issue:`29054`, and :issue:`29570`)
298299

299300
Plotting
300301
^^^^^^^^
301302

302-
-
303+
- Bug in :meth:`DataFrame.plot` where a marker letter in the ``style`` keyword sometimes causes a ``ValueError`` (:issue:`21003`)
303304
-
304305

305306
Groupby/resample/rolling

pandas/_libs/algos.pyx

+7-7
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/_typing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117

118118
# compression keywords and compression
119-
CompressionDict = Mapping[str, Optional[Union[str, int, bool]]]
119+
CompressionDict = Dict[str, Any]
120120
CompressionOptions = Optional[Union[str, CompressionDict]]
121121

122122

@@ -138,6 +138,6 @@ class IOargs(Generic[ModeVar, EncodingVar]):
138138

139139
filepath_or_buffer: FileOrBuffer
140140
encoding: EncodingVar
141-
compression: CompressionOptions
141+
compression: CompressionDict
142142
should_close: bool
143143
mode: Union[ModeVar, str]

pandas/core/algorithms.py

+4-4
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/apply.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import abc
22
import inspect
3-
from typing import TYPE_CHECKING, Any, Dict, Iterator, Optional, Tuple, Type, Union
3+
from typing import TYPE_CHECKING, Any, Dict, Iterator, Optional, Tuple, Type
44

55
import numpy as np
66

77
from pandas._config import option_context
88

9-
from pandas._typing import Axis
9+
from pandas._typing import Axis, FrameOrSeriesUnion
1010
from pandas.util._decorators import cache_readonly
1111

1212
from pandas.core.dtypes.common import is_dict_like, is_list_like, is_sequence
@@ -73,7 +73,7 @@ def series_generator(self) -> Iterator["Series"]:
7373
@abc.abstractmethod
7474
def wrap_results_for_axis(
7575
self, results: ResType, res_index: "Index"
76-
) -> Union["Series", "DataFrame"]:
76+
) -> FrameOrSeriesUnion:
7777
pass
7878

7979
# ---------------------------------------------------------------
@@ -289,9 +289,7 @@ def apply_series_generator(self) -> Tuple[ResType, "Index"]:
289289

290290
return results, res_index
291291

292-
def wrap_results(
293-
self, results: ResType, res_index: "Index"
294-
) -> Union["Series", "DataFrame"]:
292+
def wrap_results(self, results: ResType, res_index: "Index") -> FrameOrSeriesUnion:
295293
from pandas import Series
296294

297295
# see if we can infer the results
@@ -335,7 +333,7 @@ def result_columns(self) -> "Index":
335333

336334
def wrap_results_for_axis(
337335
self, results: ResType, res_index: "Index"
338-
) -> Union["Series", "DataFrame"]:
336+
) -> FrameOrSeriesUnion:
339337
""" return the results for the rows """
340338

341339
if self.result_type == "reduce":
@@ -408,9 +406,9 @@ def result_columns(self) -> "Index":
408406

409407
def wrap_results_for_axis(
410408
self, results: ResType, res_index: "Index"
411-
) -> Union["Series", "DataFrame"]:
409+
) -> FrameOrSeriesUnion:
412410
""" return the results for the columns """
413-
result: Union["Series", "DataFrame"]
411+
result: FrameOrSeriesUnion
414412

415413
# we have requested to expand
416414
if self.result_type == "expand":

pandas/core/array_algos/replace.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
import operator
55
import re
6-
from typing import Optional, Pattern, Union
6+
from typing import Pattern, Union
77

88
import numpy as np
99

@@ -14,14 +14,10 @@
1414
is_numeric_v_string_like,
1515
is_scalar,
1616
)
17-
from pandas.core.dtypes.missing import isna
1817

1918

2019
def compare_or_regex_search(
21-
a: ArrayLike,
22-
b: Union[Scalar, Pattern],
23-
regex: bool = False,
24-
mask: Optional[ArrayLike] = None,
20+
a: ArrayLike, b: Union[Scalar, Pattern], regex: bool, mask: ArrayLike,
2521
) -> Union[ArrayLike, bool]:
2622
"""
2723
Compare two array_like inputs of the same shape or two scalar values
@@ -33,8 +29,8 @@ def compare_or_regex_search(
3329
----------
3430
a : array_like
3531
b : scalar or regex pattern
36-
regex : bool, default False
37-
mask : array_like or None (default)
32+
regex : bool
33+
mask : array_like
3834
3935
Returns
4036
-------
@@ -68,8 +64,6 @@ def _check_comparison_types(
6864
)
6965

7066
# GH#32621 use mask to avoid comparing to NAs
71-
if mask is None and isinstance(a, np.ndarray) and not isinstance(b, np.ndarray):
72-
mask = np.reshape(~(isna(a)), a.shape)
7367
if isinstance(a, np.ndarray):
7468
a = a[mask]
7569

pandas/core/arrays/sparse/array.py

+1-1
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:

0 commit comments

Comments
 (0)