Skip to content

Commit 64859c1

Browse files
authored
CLN: remove unused arg from _ensure_data (#40071)
1 parent d51ee22 commit 64859c1

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

pandas/core/algorithms.py

+11-25
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@
108108
# --------------- #
109109
# dtype access #
110110
# --------------- #
111-
def _ensure_data(
112-
values: ArrayLike, dtype: Optional[DtypeObj] = None
113-
) -> Tuple[np.ndarray, DtypeObj]:
111+
def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
114112
"""
115113
routine to ensure that our data is of the correct
116114
input dtype for lower-level routines
@@ -126,43 +124,33 @@ def _ensure_data(
126124
Parameters
127125
----------
128126
values : array-like
129-
dtype : pandas_dtype, optional
130-
coerce to this dtype
131127
132128
Returns
133129
-------
134130
values : ndarray
135131
pandas_dtype : np.dtype or ExtensionDtype
136132
"""
137133

138-
if dtype is not None:
139-
# We only have non-None dtype when called from `isin`, and
140-
# both Datetimelike and Categorical dispatch before getting here.
141-
assert not needs_i8_conversion(dtype)
142-
assert not is_categorical_dtype(dtype)
143-
144134
if not isinstance(values, ABCMultiIndex):
145135
# extract_array would raise
146136
values = extract_array(values, extract_numpy=True)
147137

148138
# we check some simple dtypes first
149-
if is_object_dtype(dtype):
150-
return ensure_object(np.asarray(values)), np.dtype("object")
151-
elif is_object_dtype(values) and dtype is None:
139+
if is_object_dtype(values):
152140
return ensure_object(np.asarray(values)), np.dtype("object")
153141

154142
try:
155-
if is_bool_dtype(values) or is_bool_dtype(dtype):
143+
if is_bool_dtype(values):
156144
# we are actually coercing to uint64
157145
# until our algos support uint8 directly (see TODO)
158146
return np.asarray(values).astype("uint64"), np.dtype("bool")
159-
elif is_signed_integer_dtype(values) or is_signed_integer_dtype(dtype):
147+
elif is_signed_integer_dtype(values):
160148
return ensure_int64(values), np.dtype("int64")
161-
elif is_unsigned_integer_dtype(values) or is_unsigned_integer_dtype(dtype):
149+
elif is_unsigned_integer_dtype(values):
162150
return ensure_uint64(values), np.dtype("uint64")
163-
elif is_float_dtype(values) or is_float_dtype(dtype):
151+
elif is_float_dtype(values):
164152
return ensure_float64(values), np.dtype("float64")
165-
elif is_complex_dtype(values) or is_complex_dtype(dtype):
153+
elif is_complex_dtype(values):
166154

167155
# ignore the fact that we are casting to float
168156
# which discards complex parts
@@ -177,12 +165,12 @@ def _ensure_data(
177165
return ensure_object(values), np.dtype("object")
178166

179167
# datetimelike
180-
if needs_i8_conversion(values.dtype) or needs_i8_conversion(dtype):
181-
if is_period_dtype(values.dtype) or is_period_dtype(dtype):
168+
if needs_i8_conversion(values.dtype):
169+
if is_period_dtype(values.dtype):
182170
from pandas import PeriodIndex
183171

184172
values = PeriodIndex(values)._data
185-
elif is_timedelta64_dtype(values.dtype) or is_timedelta64_dtype(dtype):
173+
elif is_timedelta64_dtype(values.dtype):
186174
from pandas import TimedeltaIndex
187175

188176
values = TimedeltaIndex(values)._data
@@ -202,9 +190,7 @@ def _ensure_data(
202190
dtype = values.dtype
203191
return values.asi8, dtype
204192

205-
elif is_categorical_dtype(values.dtype) and (
206-
is_categorical_dtype(dtype) or dtype is None
207-
):
193+
elif is_categorical_dtype(values.dtype):
208194
values = cast("Categorical", values)
209195
values = values.codes
210196
dtype = pandas_dtype("category")

0 commit comments

Comments
 (0)