Skip to content

Commit 1270474

Browse files
committed
rebase to master
1 parent bca799d commit 1270474

File tree

11 files changed

+22
-35
lines changed

11 files changed

+22
-35
lines changed

pandas/_typing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
Frequency = Union[str, "DateOffset"]
124124
Axes = Collection[Any]
125125
RandomState = Union[int, ArrayLike, np.random.Generator, np.random.RandomState]
126-
MergeTypes = Literal['inner', 'outer', 'left', 'right', 'cross']
127-
ConcatTypes = Literal['inner', 'outer']
126+
MergeTypes = Literal["inner", "outer", "left", "right", "cross"]
127+
ConcatTypes = Literal["inner", "outer"]
128128

129129
# dtypes
130130
NpDtype = Union[str, np.dtype]

pandas/core/apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def apply_multiple(self) -> FrameOrSeriesUnion:
520520

521521
def normalize_dictlike_arg(
522522
self,
523-
how: Literal['apply', 'agg', 'transform'],
523+
how: Literal["apply", "agg", "transform"],
524524
obj: FrameOrSeriesUnion,
525525
func: AggFuncTypeDict,
526526
) -> AggFuncTypeDict:

pandas/core/arrays/_ranges.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def generate_regular_range(
7979

8080

8181
def _generate_range_overflow_safe(
82-
endpoint: int, periods: int, stride: int, side: Literal['start', 'end'] = "start"
82+
endpoint: int, periods: int, stride: int, side: Literal["start", "end"] = "start"
8383
) -> int:
8484
"""
8585
Calculate the second endpoint for passing to np.arange, checking
@@ -106,8 +106,7 @@ def _generate_range_overflow_safe(
106106
OutOfBoundsDatetime
107107
"""
108108
# GH#14187 raise instead of incorrectly wrapping around
109-
if side not in ["start", "end"]:
110-
raise ValueError('Value for side argument must be one of: start, end')
109+
assert side in ["start", "end"]
111110

112111
i64max = np.uint64(i8max)
113112
msg = f"Cannot generate range with {side}={endpoint} and periods={periods}"
@@ -147,14 +146,14 @@ def _generate_range_overflow_safe(
147146

148147

149148
def _generate_range_overflow_safe_signed(
150-
endpoint: int, periods: int, stride: int, side: Literal['start', 'end']
149+
endpoint: int, periods: int, stride: int, side: Literal["start", "end"]
151150
) -> int:
152151
"""
153152
A special case for _generate_range_overflow_safe where `periods * stride`
154153
can be calculated without overflowing int64 bounds.
155154
"""
156-
if side not in ['start', 'end']:
157-
raise ValueError('Value for side argument must be one of: start, end')
155+
assert side in ['start', 'end']
156+
158157
if side == 'end':
159158
stride *= -1
160159

pandas/core/arrays/datetimes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
lib,
2020
tslib,
2121
)
22+
from pandas._typing import (
23+
Dtype,
24+
)
2225
from pandas._libs.arrays import NDArrayBacked
2326
from pandas._libs.tslibs import (
2427
BaseOffset,
@@ -1967,7 +1970,7 @@ def sequence_to_datetimes(
19671970

19681971
def sequence_to_dt64ns(
19691972
data,
1970-
dtype: str = None,
1973+
dtype: Dtype = None,
19711974
copy: bool = False,
19721975
tz: tzinfo | str = None,
19731976
dayfirst: bool = False,

pandas/core/groupby/ops.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,7 @@ def _cython_operation(
967967
"""
968968
Returns the values of a cython operation.
969969
"""
970-
if kind not in ["transform", "aggregate"]:
971-
raise ValueError('Value for kind argument must be one of: '
972-
'transform, aggregate')
970+
assert kind in ["transform", "aggregate"]
973971

974972
cy_op = WrappedCythonOp(kind=kind, how=how)
975973

pandas/core/indexes/base.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -3651,8 +3651,7 @@ def _convert_slice_indexer(self, key: slice, kind: str_t):
36513651
key : label of the slice bound
36523652
kind : {'loc', 'getitem'}
36533653
"""
3654-
if kind not in ["loc", "getitem"]:
3655-
raise ValueError('Value for kind argument must be one of: loc, getitem')
3654+
assert kind in ["loc", "getitem"], kind
36563655

36573656
# potentially cast the bounds to integers
36583657
start, stop, step = key.start, key.stop, key.step
@@ -5679,8 +5678,7 @@ def _validate_indexer(self, form: str_t, key, kind: str_t):
56795678
If we are positional indexer, validate that we have appropriate
56805679
typed bounds must be an integer.
56815680
"""
5682-
if kind not in ["getitem", "iloc"]:
5683-
raise ValueError('Value for kind argument must be one of: getitem, iloc')
5681+
assert kind in ["getitem", "iloc"]
56845682

56855683
if key is not None and not is_integer(key):
56865684
raise self._invalid_indexer(form, key)
@@ -5710,9 +5708,7 @@ def _maybe_cast_slice_bound(
57105708
-----
57115709
Value of `side` parameter should be validated in caller.
57125710
"""
5713-
if kind not in ["loc", "getitem", None, no_default]:
5714-
raise ValueError('Value for kind argument must be one of: '
5715-
'loc, getitem or None')
5711+
assert kind in ["loc", "getitem", None, no_default]
57165712
self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound")
57175713

57185714
# We are a plain index here (sub-class override this method if they

pandas/core/indexes/datetimes.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,7 @@ def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
728728
-----
729729
Value of `side` parameter should be validated in caller.
730730
"""
731-
if kind not in ["loc", "getitem", None, lib.no_default]:
732-
raise ValueError('Value for kind argument must be one of: '
733-
'loc, getitem or None')
731+
assert kind in ["loc", "getitem", None, lib.no_default]
734732
self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound")
735733

736734
if isinstance(label, str):

pandas/core/indexes/numeric.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ def _should_fallback_to_positional(self) -> bool:
236236
@doc(Index._convert_slice_indexer)
237237
def _convert_slice_indexer(self, key: slice, kind: str):
238238
if is_float_dtype(self.dtype):
239-
if kind not in ["loc", "getitem"]:
240-
raise ValueError('Value for kind argument must be one of: loc, getitem')
239+
assert kind in ["loc", "getitem"]
241240

242241
# We always treat __getitem__ slicing as label-based
243242
# translate to locations
@@ -247,9 +246,7 @@ def _convert_slice_indexer(self, key: slice, kind: str):
247246

248247
@doc(Index._maybe_cast_slice_bound)
249248
def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
250-
if kind not in ["loc", "getitem", None, lib.no_default]:
251-
raise ValueError('Value for kind argument must be one of: '
252-
'loc, getitem or None')
249+
assert kind in ["loc", "getitem", None, lib.no_default]
253250
self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound")
254251

255252
# we will try to coerce to integers

pandas/core/indexes/period.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,7 @@ def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
480480
Value of `side` parameter should be validated in caller.
481481
482482
"""
483-
if kind not in ["loc", "getitem", None, lib.no_default]:
484-
raise ValueError('Value for kind argument must be one of: '
485-
'loc, getitem or None')
483+
assert kind in ["loc", "getitem", None, lib.no_default]
486484
self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound")
487485

488486
if isinstance(label, datetime):

pandas/core/indexes/timedeltas.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
192192
-------
193193
label : object
194194
"""
195-
if kind not in ["loc", "getitem", None, lib.no_default]:
196-
raise ValueError('Value for kind argument must be one of: '
197-
'loc, getitem or None')
195+
assert kind in ["loc", "getitem", None, lib.no_default]
198196
self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound")
199197

200198
if isinstance(label, str):

pandas/core/missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def clean_interp_method(method: str, index: Index, **kwargs) -> str:
165165
return method
166166

167167

168-
def find_valid_index(values, *, how: Literal['first', 'last']) -> int | None:
168+
def find_valid_index(values, *, how: Literal["first", "last"]) -> int | None:
169169
"""
170170
Retrieves the index of the first valid value.
171171

0 commit comments

Comments
 (0)