Skip to content

CLN: annotate #35242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/hashing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEF dROUNDS = 4


@cython.boundscheck(False)
def hash_object_array(ndarray[object] arr, object key, object encoding='utf8'):
def hash_object_array(ndarray[object] arr, str key, str encoding="utf8"):
"""
Parameters
----------
Expand Down
21 changes: 11 additions & 10 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from cpython.datetime cimport (
PyDateTime_Check,
PyDateTime_IMPORT,
datetime,
tzinfo,
)
# import datetime C API
PyDateTime_IMPORT
Expand Down Expand Up @@ -93,8 +94,8 @@ def _test_parse_iso8601(ts: str):
@cython.boundscheck(False)
def format_array_from_datetime(
ndarray[int64_t] values,
object tz=None,
object format=None,
tzinfo tz=None,
str format=None,
object na_rep=None
):
"""
Expand All @@ -103,8 +104,8 @@ def format_array_from_datetime(
Parameters
----------
values : a 1-d i8 array
tz : the timezone (or None)
format : optional, default is None
tz : tzinfo or None, default None
format : str or None, default None
a strftime capable string
na_rep : optional, default is None
a nat format
Expand Down Expand Up @@ -360,7 +361,7 @@ cpdef array_to_datetime(
str errors='raise',
bint dayfirst=False,
bint yearfirst=False,
object utc=None,
bint utc=False,
bint require_iso8601=False
):
"""
Expand All @@ -386,7 +387,7 @@ cpdef array_to_datetime(
dayfirst parsing behavior when encountering datetime strings
yearfirst : bool, default False
yearfirst parsing behavior when encountering datetime strings
utc : bool, default None
utc : bool, default False
indicator whether the dates should be UTC
require_iso8601 : bool, default False
indicator whether the datetime string should be iso8601
Expand All @@ -412,7 +413,7 @@ cpdef array_to_datetime(
bint is_same_offsets
_TSObject _ts
int64_t value
int out_local=0, out_tzoffset=0
int out_local = 0, out_tzoffset = 0
float offset_seconds, tz_offset
set out_tzoffset_vals = set()
bint string_to_dts_failed
Expand Down Expand Up @@ -659,7 +660,7 @@ cdef array_to_datetime_object(
ndarray[object] values,
str errors,
bint dayfirst=False,
bint yearfirst=False
bint yearfirst=False,
):
"""
Fall back function for array_to_datetime
Expand All @@ -671,7 +672,7 @@ cdef array_to_datetime_object(
----------
values : ndarray of object
date-like objects to convert
errors : str, default 'raise'
errors : str
error behavior when parsing
dayfirst : bool, default False
dayfirst parsing behavior when encountering datetime strings
Expand All @@ -684,7 +685,7 @@ cdef array_to_datetime_object(
"""
cdef:
Py_ssize_t i, n = len(values)
object val,
object val
bint is_ignore = errors == 'ignore'
bint is_coerce = errors == 'coerce'
bint is_raise = errors == 'raise'
Expand Down
24 changes: 12 additions & 12 deletions pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import locale
import calendar
import re

from cpython cimport datetime
from cpython.datetime cimport date, tzinfo

from _thread import allocate_lock as _thread_allocate_lock

Expand Down Expand Up @@ -291,20 +291,20 @@ def array_strptime(object[:] values, object fmt, bint exact=True, errors='raise'
elif iso_year != -1 and iso_week != -1:
year, julian = _calc_julian_from_V(iso_year, iso_week,
weekday + 1)
# Cannot pre-calculate datetime.date() since can change in Julian
# Cannot pre-calculate date() since can change in Julian
# calculation and thus could have different value for the day of the wk
# calculation.
try:
if julian == -1:
# Need to add 1 to result since first day of the year is 1, not
# 0.
ordinal = datetime.date(year, month, day).toordinal()
julian = ordinal - datetime.date(year, 1, 1).toordinal() + 1
ordinal = date(year, month, day).toordinal()
julian = ordinal - date(year, 1, 1).toordinal() + 1
else:
# Assume that if they bothered to include Julian day it will
# be accurate.
datetime_result = datetime.date.fromordinal(
(julian - 1) + datetime.date(year, 1, 1).toordinal())
datetime_result = date.fromordinal(
(julian - 1) + date(year, 1, 1).toordinal())
year = datetime_result.year
month = datetime_result.month
day = datetime_result.day
Expand All @@ -314,7 +314,7 @@ def array_strptime(object[:] values, object fmt, bint exact=True, errors='raise'
continue
raise
if weekday == -1:
weekday = datetime.date(year, month, day).weekday()
weekday = date(year, month, day).weekday()

dts.year = year
dts.month = month
Expand Down Expand Up @@ -652,7 +652,7 @@ cdef int _calc_julian_from_U_or_W(int year, int week_of_year,
cdef:
int first_weekday, week_0_length, days_to_week

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

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


cdef parse_timezone_directive(str z):
cdef tzinfo parse_timezone_directive(str z):
"""
Parse the '%z' directive and return a pytz.FixedOffset

Expand Down