Skip to content

Commit 182643d

Browse files
committed
Merge branch 'master' into ind-sort-values
2 parents a783de9 + 1a576eb commit 182643d

Some content is hidden

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

49 files changed

+535
-535
lines changed

pandas/_testing.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def assert_categorical_equal(
939939
if check_category_order:
940940
assert_index_equal(left.categories, right.categories, obj=f"{obj}.categories")
941941
assert_numpy_array_equal(
942-
left.codes, right.codes, check_dtype=check_dtype, obj=f"{obj}.codes",
942+
left.codes, right.codes, check_dtype=check_dtype, obj=f"{obj}.codes"
943943
)
944944
else:
945945
try:
@@ -948,9 +948,7 @@ def assert_categorical_equal(
948948
except TypeError:
949949
# e.g. '<' not supported between instances of 'int' and 'str'
950950
lc, rc = left.categories, right.categories
951-
assert_index_equal(
952-
lc, rc, obj=f"{obj}.categories",
953-
)
951+
assert_index_equal(lc, rc, obj=f"{obj}.categories")
954952
assert_index_equal(
955953
left.categories.take(left.codes),
956954
right.categories.take(right.codes),
@@ -1092,7 +1090,7 @@ def _raise(left, right, err_msg):
10921090
if err_msg is None:
10931091
if left.shape != right.shape:
10941092
raise_assert_detail(
1095-
obj, f"{obj} shapes are different", left.shape, right.shape,
1093+
obj, f"{obj} shapes are different", left.shape, right.shape
10961094
)
10971095

10981096
diff = 0
@@ -1559,7 +1557,7 @@ def assert_frame_equal(
15591557
# shape comparison
15601558
if left.shape != right.shape:
15611559
raise_assert_detail(
1562-
obj, f"{obj} shape mismatch", f"{repr(left.shape)}", f"{repr(right.shape)}",
1560+
obj, f"{obj} shape mismatch", f"{repr(left.shape)}", f"{repr(right.shape)}"
15631561
)
15641562

15651563
if check_like:
@@ -2884,7 +2882,7 @@ def convert_rows_list_to_csv_str(rows_list: List[str]):
28842882
return expected
28852883

28862884

2887-
def external_error_raised(expected_exception: Type[Exception],) -> ContextManager:
2885+
def external_error_raised(expected_exception: Type[Exception]) -> ContextManager:
28882886
"""
28892887
Helper function to mark pytest.raises that have an external error message.
28902888

pandas/core/aggregation.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,27 @@
1010
Callable,
1111
DefaultDict,
1212
Dict,
13+
Iterable,
1314
List,
1415
Optional,
1516
Sequence,
1617
Tuple,
1718
Union,
1819
)
1920

20-
from pandas._typing import AggFuncType, Label
21+
from pandas._typing import AggFuncType, FrameOrSeries, Label
2122

2223
from pandas.core.dtypes.common import is_dict_like, is_list_like
2324

2425
from pandas.core.base import SpecificationError
2526
import pandas.core.common as com
2627
from pandas.core.indexes.api import Index
27-
from pandas.core.series import FrameOrSeriesUnion, Series
28+
from pandas.core.series import Series
2829

2930

3031
def reconstruct_func(
31-
func: Optional[AggFuncType], **kwargs,
32-
) -> Tuple[
33-
bool, Optional[AggFuncType], Optional[List[str]], Optional[List[int]],
34-
]:
32+
func: Optional[AggFuncType], **kwargs
33+
) -> Tuple[bool, Optional[AggFuncType], Optional[List[str]], Optional[List[int]]]:
3534
"""
3635
This is the internal function to reconstruct func given if there is relabeling
3736
or not and also normalize the keyword to get new order of columns.
@@ -278,12 +277,13 @@ def maybe_mangle_lambdas(agg_spec: Any) -> Any:
278277

279278

280279
def relabel_result(
281-
result: FrameOrSeriesUnion,
280+
result: FrameOrSeries,
282281
func: Dict[str, List[Union[Callable, str]]],
283-
columns: Tuple,
284-
order: List[int],
282+
columns: Iterable[Label],
283+
order: Iterable[int],
285284
) -> Dict[Label, Series]:
286-
"""Internal function to reorder result if relabelling is True for
285+
"""
286+
Internal function to reorder result if relabelling is True for
287287
dataframe.agg, and return the reordered result in dict.
288288
289289
Parameters:

pandas/core/algorithms.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
from pandas._libs import Timestamp, algos, hashtable as htable, iNaT, lib
13-
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj
13+
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj, FrameOrSeriesUnion
1414
from pandas.util._decorators import doc
1515

1616
from pandas.core.dtypes.cast import (
@@ -58,7 +58,7 @@
5858
from pandas.core.indexers import validate_indices
5959

6060
if TYPE_CHECKING:
61-
from pandas import Series
61+
from pandas import DataFrame, Series
6262

6363
_shared_docs: Dict[str, str] = {}
6464

@@ -462,7 +462,7 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray:
462462

463463

464464
def _factorize_array(
465-
values, na_sentinel: int = -1, size_hint=None, na_value=None, mask=None,
465+
values, na_sentinel: int = -1, size_hint=None, na_value=None, mask=None
466466
) -> Tuple[np.ndarray, np.ndarray]:
467467
"""
468468
Factorize an array-like to codes and uniques.
@@ -1101,6 +1101,9 @@ def __init__(self, obj, n: int, keep: str):
11011101
if self.keep not in ("first", "last", "all"):
11021102
raise ValueError('keep must be either "first", "last" or "all"')
11031103

1104+
def compute(self, method: str) -> FrameOrSeriesUnion:
1105+
raise NotImplementedError
1106+
11041107
def nlargest(self):
11051108
return self.compute("nlargest")
11061109

@@ -1133,7 +1136,7 @@ class SelectNSeries(SelectN):
11331136
nordered : Series
11341137
"""
11351138

1136-
def compute(self, method):
1139+
def compute(self, method: str) -> "Series":
11371140

11381141
n = self.n
11391142
dtype = self.obj.dtype
@@ -1207,7 +1210,7 @@ def __init__(self, obj, n: int, keep: str, columns):
12071210
columns = list(columns)
12081211
self.columns = columns
12091212

1210-
def compute(self, method):
1213+
def compute(self, method: str) -> "DataFrame":
12111214

12121215
from pandas import Int64Index
12131216

pandas/core/arrays/_mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def take(
4040
fill_value = self._validate_fill_value(fill_value)
4141

4242
new_data = take(
43-
self._ndarray, indices, allow_fill=allow_fill, fill_value=fill_value,
43+
self._ndarray, indices, allow_fill=allow_fill, fill_value=fill_value
4444
)
4545
return self._from_backing_data(new_data)
4646

pandas/core/arrays/base.py

+12
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@ class ExtensionOpsMixin:
11671167
with NumPy arrays.
11681168
"""
11691169

1170+
@classmethod
1171+
def _create_arithmetic_method(cls, op):
1172+
raise AbstractMethodError(cls)
1173+
11701174
@classmethod
11711175
def _add_arithmetic_ops(cls):
11721176
cls.__add__ = cls._create_arithmetic_method(operator.add)
@@ -1186,6 +1190,10 @@ def _add_arithmetic_ops(cls):
11861190
cls.__divmod__ = cls._create_arithmetic_method(divmod)
11871191
cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod)
11881192

1193+
@classmethod
1194+
def _create_comparison_method(cls, op):
1195+
raise AbstractMethodError(cls)
1196+
11891197
@classmethod
11901198
def _add_comparison_ops(cls):
11911199
cls.__eq__ = cls._create_comparison_method(operator.eq)
@@ -1195,6 +1203,10 @@ def _add_comparison_ops(cls):
11951203
cls.__le__ = cls._create_comparison_method(operator.le)
11961204
cls.__ge__ = cls._create_comparison_method(operator.ge)
11971205

1206+
@classmethod
1207+
def _create_logical_method(cls, op):
1208+
raise AbstractMethodError(cls)
1209+
11981210
@classmethod
11991211
def _add_logical_ops(cls):
12001212
cls.__and__ = cls._create_logical_method(operator.and_)

pandas/core/arrays/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ def argsort(self, ascending=True, kind="quicksort", **kwargs):
15051505
return super().argsort(ascending=ascending, kind=kind, **kwargs)
15061506

15071507
def sort_values(
1508-
self, inplace: bool = False, ascending: bool = True, na_position: str = "last",
1508+
self, inplace: bool = False, ascending: bool = True, na_position: str = "last"
15091509
):
15101510
"""
15111511
Sort the Categorical by category value returning a new

pandas/core/arrays/integer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __from_arrow__(
138138
return IntegerArray._concat_same_type(results)
139139

140140

141-
def integer_array(values, dtype=None, copy: bool = False,) -> "IntegerArray":
141+
def integer_array(values, dtype=None, copy: bool = False) -> "IntegerArray":
142142
"""
143143
Infer and return an integer array of the values.
144144
@@ -182,7 +182,7 @@ def safe_cast(values, dtype, copy: bool):
182182

183183

184184
def coerce_to_array(
185-
values, dtype, mask=None, copy: bool = False,
185+
values, dtype, mask=None, copy: bool = False
186186
) -> Tuple[np.ndarray, np.ndarray]:
187187
"""
188188
Coerce the input values array to numpy arrays with a mask

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __invert__(self: BaseMaskedArrayT) -> BaseMaskedArrayT:
126126
return type(self)(~self._data, self._mask)
127127

128128
def to_numpy(
129-
self, dtype=None, copy: bool = False, na_value: Scalar = lib.no_default,
129+
self, dtype=None, copy: bool = False, na_value: Scalar = lib.no_default
130130
) -> np.ndarray:
131131
"""
132132
Convert to a NumPy Array.

pandas/core/arrays/numpy_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def isna(self) -> np.ndarray:
280280
return isna(self._ndarray)
281281

282282
def fillna(
283-
self, value=None, method: Optional[str] = None, limit: Optional[int] = None,
283+
self, value=None, method: Optional[str] = None, limit: Optional[int] = None
284284
) -> "PandasArray":
285285
# TODO(_values_for_fillna): remove this
286286
value, method = validate_fillna_kwargs(value, method)

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def _sub_period_array(self, other):
634634
return new_values
635635

636636
def _addsub_int_array(
637-
self, other: np.ndarray, op: Callable[[Any, Any], Any],
637+
self, other: np.ndarray, op: Callable[[Any, Any], Any]
638638
) -> "PeriodArray":
639639
"""
640640
Add or subtract array of integers; equivalent to applying

pandas/core/construction.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,7 @@ def sanitize_array(
514514
return subarr
515515

516516

517-
def _try_cast(
518-
arr, dtype: Optional[DtypeObj], copy: bool, raise_cast_failure: bool,
519-
):
517+
def _try_cast(arr, dtype: Optional[DtypeObj], copy: bool, raise_cast_failure: bool):
520518
"""
521519
Convert input to numpy ndarray and optionally cast to a given dtype.
522520

pandas/core/frame.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7415,6 +7415,12 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
74157415
if relabeling:
74167416
# This is to keep the order to columns occurrence unchanged, and also
74177417
# keep the order of new columns occurrence unchanged
7418+
7419+
# For the return values of reconstruct_func, if relabeling is
7420+
# False, columns and order will be None.
7421+
assert columns is not None
7422+
assert order is not None
7423+
74187424
result_in_dict = relabel_result(result, func, columns, order)
74197425
result = DataFrame(result_in_dict, index=columns)
74207426

@@ -9306,7 +9312,6 @@ def _AXIS_NAMES(self) -> Dict[int, str]:
93069312

93079313

93089314
DataFrame._add_numeric_operations()
9309-
DataFrame._add_series_or_dataframe_operations()
93109315

93119316
ops.add_flex_arithmetic_methods(DataFrame)
93129317
ops.add_special_arithmetic_methods(DataFrame)

0 commit comments

Comments
 (0)