Skip to content

Commit cbe1b32

Browse files
authored
CLN: assorted (#56431)
* CLN: assorted * CLN: assorted * revert bit * revert bit again * mypy fixup * revert
1 parent db6fd22 commit cbe1b32

File tree

22 files changed

+50
-54
lines changed

22 files changed

+50
-54
lines changed

pandas/_libs/tslib.pyx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def array_with_unit_to_datetime(
338338
f"unit='{unit}' not valid with non-numerical val='{val}'"
339339
)
340340

341-
except (ValueError, OutOfBoundsDatetime, TypeError) as err:
341+
except (ValueError, TypeError) as err:
342342
if is_raise:
343343
err.args = (f"{err}, at position {i}",)
344344
raise
@@ -435,15 +435,15 @@ cpdef array_to_datetime(
435435
Parameters
436436
----------
437437
values : ndarray of object
438-
date-like objects to convert
438+
date-like objects to convert
439439
errors : str, default 'raise'
440-
error behavior when parsing
440+
error behavior when parsing
441441
dayfirst : bool, default False
442-
dayfirst parsing behavior when encountering datetime strings
442+
dayfirst parsing behavior when encountering datetime strings
443443
yearfirst : bool, default False
444-
yearfirst parsing behavior when encountering datetime strings
444+
yearfirst parsing behavior when encountering datetime strings
445445
utc : bool, default False
446-
indicator whether the dates should be UTC
446+
indicator whether the dates should be UTC
447447
creso : NPY_DATETIMEUNIT, default NPY_FR_ns
448448
Set to NPY_FR_GENERIC to infer a resolution.
449449
@@ -464,7 +464,7 @@ cpdef array_to_datetime(
464464
bint is_ignore = errors == "ignore"
465465
bint is_coerce = errors == "coerce"
466466
bint is_same_offsets
467-
_TSObject _ts
467+
_TSObject tsobj
468468
float tz_offset
469469
set out_tzoffset_vals = set()
470470
tzinfo tz, tz_out = None
@@ -550,29 +550,28 @@ cpdef array_to_datetime(
550550
creso = state.creso
551551
continue
552552

553-
_ts = convert_str_to_tsobject(
553+
tsobj = convert_str_to_tsobject(
554554
val, None, dayfirst=dayfirst, yearfirst=yearfirst
555555
)
556556

557-
if _ts.value == NPY_NAT:
557+
if tsobj.value == NPY_NAT:
558558
# e.g. "NaT" string or empty string, we do not consider
559559
# this as either tzaware or tznaive. See
560560
# test_to_datetime_with_empty_str_utc_false_format_mixed
561561
# We also do not update resolution inference based on this,
562562
# see test_infer_with_nat_int_float_str
563-
iresult[i] = _ts.value
563+
iresult[i] = tsobj.value
564564
continue
565565

566-
item_reso = _ts.creso
566+
item_reso = tsobj.creso
567567
state.update_creso(item_reso)
568568
if infer_reso:
569569
creso = state.creso
570570

571-
_ts.ensure_reso(creso, val)
572-
573-
iresult[i] = _ts.value
571+
tsobj.ensure_reso(creso, val)
572+
iresult[i] = tsobj.value
574573

575-
tz = _ts.tzinfo
574+
tz = tsobj.tzinfo
576575
if tz is not None:
577576
# dateutil timezone objects cannot be hashed, so
578577
# store the UTC offsets in seconds instead

pandas/_libs/tslibs/conversion.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ from cpython.datetime cimport (
2929
import_datetime()
3030

3131
from pandas._libs.missing cimport checknull_with_nat_and_na
32-
from pandas._libs.tslibs.base cimport ABCTimestamp
3332
from pandas._libs.tslibs.dtypes cimport (
3433
abbrev_to_npy_unit,
3534
get_supported_reso,
@@ -492,7 +491,7 @@ cdef _TSObject convert_datetime_to_tsobject(
492491
pydatetime_to_dtstruct(ts, &obj.dts)
493492
obj.tzinfo = ts.tzinfo
494493

495-
if isinstance(ts, ABCTimestamp):
494+
if isinstance(ts, _Timestamp):
496495
obj.dts.ps = ts.nanosecond * 1000
497496

498497
if nanos:
@@ -766,7 +765,7 @@ cpdef inline datetime localize_pydatetime(datetime dt, tzinfo tz):
766765
"""
767766
if tz is None:
768767
return dt
769-
elif isinstance(dt, ABCTimestamp):
768+
elif isinstance(dt, _Timestamp):
770769
return dt.tz_localize(tz)
771770
return _localize_pydatetime(dt, tz)
772771

pandas/_libs/tslibs/dtypes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OFFSET_TO_PERIOD_FREQSTR: dict[str, str]
44

55
def periods_per_day(reso: int = ...) -> int: ...
66
def periods_per_second(reso: int) -> int: ...
7-
def abbrev_to_npy_unit(abbrev: str) -> int: ...
7+
def abbrev_to_npy_unit(abbrev: str | None) -> int: ...
88
def freq_to_period_freqstr(freq_n: int, freq_name: str) -> str: ...
99

1010
class PeriodDtypeBase:

pandas/_libs/tslibs/np_datetime.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ cdef int64_t get_conversion_factor(
596596
):
597597
raise ValueError("unit-less resolutions are not supported")
598598
if from_unit > to_unit:
599-
raise ValueError
599+
raise ValueError("from_unit must be <= to_unit")
600600

601601
if from_unit == to_unit:
602602
return 1

pandas/_libs/tslibs/strptime.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ def array_strptime(
319319
Py_ssize_t i, n = len(values)
320320
npy_datetimestruct dts
321321
int64_t[::1] iresult
322-
object val, tz
322+
object val
323323
bint seen_datetime_offset = False
324324
bint is_raise = errors=="raise"
325325
bint is_ignore = errors=="ignore"
326326
bint is_coerce = errors=="coerce"
327327
bint is_same_offsets
328328
set out_tzoffset_vals = set()
329-
tzinfo tz_out = None
329+
tzinfo tz, tz_out = None
330330
bint iso_format = format_is_iso(fmt)
331331
NPY_DATETIMEUNIT out_bestunit, item_reso
332332
int out_local = 0, out_tzoffset = 0
@@ -484,7 +484,7 @@ def array_strptime(
484484
tz = None
485485
out_tzoffset_vals.add("naive")
486486

487-
except (ValueError, OutOfBoundsDatetime) as ex:
487+
except ValueError as ex:
488488
ex.args = (
489489
f"{str(ex)}, at position {i}. You might want to try:\n"
490490
" - passing `format` if your strings have a consistent format;\n"
@@ -1084,7 +1084,7 @@ cdef tzinfo parse_timezone_directive(str z):
10841084
cdef:
10851085
int hours, minutes, seconds, pad_number, microseconds
10861086
int total_minutes
1087-
object gmtoff_remainder, gmtoff_remainder_padding
1087+
str gmtoff_remainder, gmtoff_remainder_padding
10881088

10891089
if z == "Z":
10901090
return timezone(timedelta(0))

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ cdef int64_t parse_timedelta_string(str ts) except? -1:
499499
"""
500500

501501
cdef:
502-
unicode c
502+
str c
503503
bint neg = 0, have_dot = 0, have_value = 0, have_hhmmss = 0
504-
object current_unit = None
504+
str current_unit = None
505505
int64_t result = 0, m = 0, r
506506
list number = [], frac = [], unit = []
507507

pandas/core/dtypes/dtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ class NumpyEADtype(ExtensionDtype):
14531453

14541454
def __init__(self, dtype: npt.DTypeLike | NumpyEADtype | None) -> None:
14551455
if isinstance(dtype, NumpyEADtype):
1456-
# make constructor univalent
1456+
# make constructor idempotent
14571457
dtype = dtype.numpy_dtype
14581458
self._dtype = np.dtype(dtype)
14591459

pandas/core/frame.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@
143143
from pandas.core.arrays.sparse import SparseFrameAccessor
144144
from pandas.core.construction import (
145145
ensure_wrapped_if_datetimelike,
146-
extract_array,
147146
sanitize_array,
148147
sanitize_masked_array,
149148
)
@@ -8784,11 +8783,11 @@ def combine_first(self, other: DataFrame) -> DataFrame:
87848783
"""
87858784
from pandas.core.computation import expressions
87868785

8787-
def combiner(x, y):
8788-
mask = extract_array(isna(x))
8786+
def combiner(x: Series, y: Series):
8787+
mask = x.isna()._values
87898788

8790-
x_values = extract_array(x, extract_numpy=True)
8791-
y_values = extract_array(y, extract_numpy=True)
8789+
x_values = x._values
8790+
y_values = y._values
87928791

87938792
# If the column y in other DataFrame is not in first DataFrame,
87948793
# just return y_values.

pandas/core/tools/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ def coerce(values):
12011201
values = to_numeric(values, errors=errors)
12021202

12031203
# prevent overflow in case of int8 or int16
1204-
if is_integer_dtype(values):
1204+
if is_integer_dtype(values.dtype):
12051205
values = values.astype("int64", copy=False)
12061206
return values
12071207

pandas/io/sas/sas7bdat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _convert_datetimes(sas_datetimes: pd.Series, unit: str) -> pd.Series:
8686
----------
8787
sas_datetimes : {Series, Sequence[float]}
8888
Dates or datetimes in SAS
89-
unit : {str}
89+
unit : {'d', 's'}
9090
"d" if the floats represent dates, "s" for datetimes
9191
9292
Returns

0 commit comments

Comments
 (0)