Skip to content

Commit a11dc79

Browse files
authored
CLN: remove never-hit branch from maybe_infer_to_datetimelike (#40109)
1 parent 48d1112 commit a11dc79

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

pandas/_libs/lib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ def infer_datetimelike_array(arr: ndarray[object]) -> str:
15621562
seen_tz_aware = True
15631563

15641564
if seen_tz_naive and seen_tz_aware:
1565-
return 'mixed'
1565+
return "mixed"
15661566
elif util.is_datetime64_object(v):
15671567
# np.datetime64
15681568
seen_datetime = True

pandas/core/dtypes/cast.py

+8-19
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def maybe_promote(dtype: np.dtype, fill_value=np.nan):
698698
return dtype, fill_value
699699

700700

701-
def _ensure_dtype_type(value, dtype: DtypeObj):
701+
def _ensure_dtype_type(value, dtype: np.dtype):
702702
"""
703703
Ensure that the given value is an instance of the given dtype.
704704
@@ -708,21 +708,17 @@ def _ensure_dtype_type(value, dtype: DtypeObj):
708708
Parameters
709709
----------
710710
value : object
711-
dtype : np.dtype or ExtensionDtype
711+
dtype : np.dtype
712712
713713
Returns
714714
-------
715715
object
716716
"""
717717
# Start with exceptions in which we do _not_ cast to numpy types
718-
if is_extension_array_dtype(dtype):
719-
return value
720-
elif dtype == np.object_:
721-
return value
722-
elif isna(value):
723-
# e.g. keep np.nan rather than try to cast to np.float32(np.nan)
718+
if dtype == np.object_:
724719
return value
725720

721+
# Note: before we get here we have already excluded isna(value)
726722
return dtype.type(value)
727723

728724

@@ -1139,7 +1135,7 @@ def astype_nansafe(
11391135
if isinstance(dtype, ExtensionDtype):
11401136
return dtype.construct_array_type()._from_sequence(arr, dtype=dtype, copy=copy)
11411137

1142-
elif not isinstance(dtype, np.dtype):
1138+
elif not isinstance(dtype, np.dtype): # pragma: no cover
11431139
raise ValueError("dtype must be np.dtype or ExtensionDtype")
11441140

11451141
if arr.dtype.kind in ["m", "M"] and (
@@ -1389,9 +1385,7 @@ def maybe_castable(dtype: np.dtype) -> bool:
13891385
return dtype.name not in POSSIBLY_CAST_DTYPES
13901386

13911387

1392-
def maybe_infer_to_datetimelike(
1393-
value: Union[np.ndarray, List], convert_dates: bool = False
1394-
):
1388+
def maybe_infer_to_datetimelike(value: Union[np.ndarray, List]):
13951389
"""
13961390
we might have a array (or single object) that is datetime like,
13971391
and no dtype is passed don't change the value unless we find a
@@ -1403,13 +1397,10 @@ def maybe_infer_to_datetimelike(
14031397
Parameters
14041398
----------
14051399
value : np.ndarray or list
1406-
convert_dates : bool, default False
1407-
if True try really hard to convert dates (such as datetime.date), other
1408-
leave inferred dtype 'date' alone
14091400
14101401
"""
14111402
if not isinstance(value, (np.ndarray, list)):
1412-
raise TypeError(type(value))
1403+
raise TypeError(type(value)) # pragma: no cover
14131404

14141405
v = np.array(value, copy=False)
14151406

@@ -1466,9 +1457,7 @@ def try_timedelta(v: np.ndarray) -> np.ndarray:
14661457

14671458
inferred_type = lib.infer_datetimelike_array(ensure_object(v))
14681459

1469-
if inferred_type == "date" and convert_dates:
1470-
value = try_datetime(v)
1471-
elif inferred_type == "datetime":
1460+
if inferred_type == "datetime":
14721461
value = try_datetime(v)
14731462
elif inferred_type == "timedelta":
14741463
value = try_timedelta(v)

pandas/core/tools/datetimes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ def _convert_and_box_cache(
248248
return _box_as_indexlike(result, utc=None, name=name)
249249

250250

251-
def _return_parsed_timezone_results(result, timezones, tz, name):
251+
def _return_parsed_timezone_results(result: np.ndarray, timezones, tz, name) -> Index:
252252
"""
253253
Return results from array_strptime if a %z or %Z directive was passed.
254254
255255
Parameters
256256
----------
257-
result : ndarray
257+
result : ndarray[int64]
258258
int64 date representations of the dates
259259
timezones : ndarray
260260
pytz timezone objects
@@ -287,7 +287,7 @@ def _convert_listlike_datetimes(
287287
infer_datetime_format: Optional[bool] = None,
288288
dayfirst: Optional[bool] = None,
289289
yearfirst: Optional[bool] = None,
290-
exact: Optional[bool] = None,
290+
exact: bool = True,
291291
):
292292
"""
293293
Helper function for to_datetime. Performs the conversions of 1D listlike
@@ -311,7 +311,7 @@ def _convert_listlike_datetimes(
311311
dayfirst parsing behavior from to_datetime
312312
yearfirst : boolean
313313
yearfirst parsing behavior from to_datetime
314-
exact : boolean
314+
exact : bool, default True
315315
exact format matching behavior from to_datetime
316316
317317
Returns

0 commit comments

Comments
 (0)