Skip to content

Commit 49097bd

Browse files
jbrockmendelfangchenli
authored andcommitted
CLN: annotate (pandas-dev#35242)
1 parent 3537637 commit 49097bd

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

pandas/_libs/hashing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DEF dROUNDS = 4
1515

1616

1717
@cython.boundscheck(False)
18-
def hash_object_array(ndarray[object] arr, object key, object encoding='utf8'):
18+
def hash_object_array(ndarray[object] arr, str key, str encoding="utf8"):
1919
"""
2020
Parameters
2121
----------

pandas/_libs/tslib.pyx

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from cpython.datetime cimport (
55
PyDateTime_Check,
66
PyDateTime_IMPORT,
77
datetime,
8+
tzinfo,
89
)
910
# import datetime C API
1011
PyDateTime_IMPORT
@@ -93,8 +94,8 @@ def _test_parse_iso8601(ts: str):
9394
@cython.boundscheck(False)
9495
def format_array_from_datetime(
9596
ndarray[int64_t] values,
96-
object tz=None,
97-
object format=None,
97+
tzinfo tz=None,
98+
str format=None,
9899
object na_rep=None
99100
):
100101
"""
@@ -103,8 +104,8 @@ def format_array_from_datetime(
103104
Parameters
104105
----------
105106
values : a 1-d i8 array
106-
tz : the timezone (or None)
107-
format : optional, default is None
107+
tz : tzinfo or None, default None
108+
format : str or None, default None
108109
a strftime capable string
109110
na_rep : optional, default is None
110111
a nat format
@@ -360,7 +361,7 @@ cpdef array_to_datetime(
360361
str errors='raise',
361362
bint dayfirst=False,
362363
bint yearfirst=False,
363-
object utc=None,
364+
bint utc=False,
364365
bint require_iso8601=False
365366
):
366367
"""
@@ -386,7 +387,7 @@ cpdef array_to_datetime(
386387
dayfirst parsing behavior when encountering datetime strings
387388
yearfirst : bool, default False
388389
yearfirst parsing behavior when encountering datetime strings
389-
utc : bool, default None
390+
utc : bool, default False
390391
indicator whether the dates should be UTC
391392
require_iso8601 : bool, default False
392393
indicator whether the datetime string should be iso8601
@@ -412,7 +413,7 @@ cpdef array_to_datetime(
412413
bint is_same_offsets
413414
_TSObject _ts
414415
int64_t value
415-
int out_local=0, out_tzoffset=0
416+
int out_local = 0, out_tzoffset = 0
416417
float offset_seconds, tz_offset
417418
set out_tzoffset_vals = set()
418419
bint string_to_dts_failed
@@ -659,7 +660,7 @@ cdef array_to_datetime_object(
659660
ndarray[object] values,
660661
str errors,
661662
bint dayfirst=False,
662-
bint yearfirst=False
663+
bint yearfirst=False,
663664
):
664665
"""
665666
Fall back function for array_to_datetime
@@ -671,7 +672,7 @@ cdef array_to_datetime_object(
671672
----------
672673
values : ndarray of object
673674
date-like objects to convert
674-
errors : str, default 'raise'
675+
errors : str
675676
error behavior when parsing
676677
dayfirst : bool, default False
677678
dayfirst parsing behavior when encountering datetime strings
@@ -684,7 +685,7 @@ cdef array_to_datetime_object(
684685
"""
685686
cdef:
686687
Py_ssize_t i, n = len(values)
687-
object val,
688+
object val
688689
bint is_ignore = errors == 'ignore'
689690
bint is_coerce = errors == 'coerce'
690691
bint is_raise = errors == 'raise'

pandas/_libs/tslibs/strptime.pyx

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import locale
55
import calendar
66
import re
77

8-
from cpython cimport datetime
8+
from cpython.datetime cimport date, tzinfo
99

1010
from _thread import allocate_lock as _thread_allocate_lock
1111

@@ -291,20 +291,20 @@ def array_strptime(object[:] values, object fmt, bint exact=True, errors='raise'
291291
elif iso_year != -1 and iso_week != -1:
292292
year, julian = _calc_julian_from_V(iso_year, iso_week,
293293
weekday + 1)
294-
# Cannot pre-calculate datetime.date() since can change in Julian
294+
# Cannot pre-calculate date() since can change in Julian
295295
# calculation and thus could have different value for the day of the wk
296296
# calculation.
297297
try:
298298
if julian == -1:
299299
# Need to add 1 to result since first day of the year is 1, not
300300
# 0.
301-
ordinal = datetime.date(year, month, day).toordinal()
302-
julian = ordinal - datetime.date(year, 1, 1).toordinal() + 1
301+
ordinal = date(year, month, day).toordinal()
302+
julian = ordinal - date(year, 1, 1).toordinal() + 1
303303
else:
304304
# Assume that if they bothered to include Julian day it will
305305
# be accurate.
306-
datetime_result = datetime.date.fromordinal(
307-
(julian - 1) + datetime.date(year, 1, 1).toordinal())
306+
datetime_result = date.fromordinal(
307+
(julian - 1) + date(year, 1, 1).toordinal())
308308
year = datetime_result.year
309309
month = datetime_result.month
310310
day = datetime_result.day
@@ -314,7 +314,7 @@ def array_strptime(object[:] values, object fmt, bint exact=True, errors='raise'
314314
continue
315315
raise
316316
if weekday == -1:
317-
weekday = datetime.date(year, month, day).weekday()
317+
weekday = date(year, month, day).weekday()
318318

319319
dts.year = year
320320
dts.month = month
@@ -652,7 +652,7 @@ cdef int _calc_julian_from_U_or_W(int year, int week_of_year,
652652
cdef:
653653
int first_weekday, week_0_length, days_to_week
654654

655-
first_weekday = datetime.date(year, 1, 1).weekday()
655+
first_weekday = date(year, 1, 1).weekday()
656656
# If we are dealing with the %U directive (week starts on Sunday), it's
657657
# easier to just shift the view to Sunday being the first day of the
658658
# week.
@@ -695,18 +695,18 @@ cdef (int, int) _calc_julian_from_V(int iso_year, int iso_week, int iso_weekday)
695695
cdef:
696696
int correction, ordinal
697697

698-
correction = datetime.date(iso_year, 1, 4).isoweekday() + 3
698+
correction = date(iso_year, 1, 4).isoweekday() + 3
699699
ordinal = (iso_week * 7) + iso_weekday - correction
700700
# ordinal may be negative or 0 now, which means the date is in the previous
701701
# calendar year
702702
if ordinal < 1:
703-
ordinal += datetime.date(iso_year, 1, 1).toordinal()
703+
ordinal += date(iso_year, 1, 1).toordinal()
704704
iso_year -= 1
705-
ordinal -= datetime.date(iso_year, 1, 1).toordinal()
705+
ordinal -= date(iso_year, 1, 1).toordinal()
706706
return iso_year, ordinal
707707

708708

709-
cdef parse_timezone_directive(str z):
709+
cdef tzinfo parse_timezone_directive(str z):
710710
"""
711711
Parse the '%z' directive and return a pytz.FixedOffset
712712

0 commit comments

Comments
 (0)