Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cdef inline int64_t cast_from_unit(object ts, str unit) except? -1:
return <int64_t>(base * m) + <int64_t>(frac * m)


cpdef inline object precision_from_unit(str unit):
cpdef inline (int64_t, int) precision_from_unit(str unit):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a union of types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, its returning a tuple

"""
Return a casting of the unit represented to nanoseconds + the precision
to round the fractional part.
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def build_field_sarray(const int64_t[:] dtindex):

@cython.wraparound(False)
@cython.boundscheck(False)
def get_date_name_field(const int64_t[:] dtindex, object field, object locale=None):
def get_date_name_field(const int64_t[:] dtindex, str field, object locale=None):
"""
Given a int64-based datetime index, return array of strings of date
name based on requested field (e.g. day_name)
Expand Down Expand Up @@ -141,7 +141,7 @@ def get_date_name_field(const int64_t[:] dtindex, object field, object locale=No

@cython.wraparound(False)
@cython.boundscheck(False)
def get_start_end_field(const int64_t[:] dtindex, object field,
def get_start_end_field(const int64_t[:] dtindex, str field,
object freqstr=None, int month_kw=12):
"""
Given an int64-based datetime index return array of indicators
Expand Down Expand Up @@ -386,7 +386,7 @@ def get_start_end_field(const int64_t[:] dtindex, object field,

@cython.wraparound(False)
@cython.boundscheck(False)
def get_date_field(const int64_t[:] dtindex, object field):
def get_date_field(const int64_t[:] dtindex, str field):
"""
Given a int64-based datetime index, extract the year, month, etc.,
field and return an array of these values.
Expand Down Expand Up @@ -548,7 +548,7 @@ def get_date_field(const int64_t[:] dtindex, object field):

@cython.wraparound(False)
@cython.boundscheck(False)
def get_timedelta_field(const int64_t[:] tdindex, object field):
def get_timedelta_field(const int64_t[:] tdindex, str field):
"""
Given a int64-based timedelta index, extract the days, hrs, sec.,
field and return an array of these values.
Expand Down
20 changes: 10 additions & 10 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ _nat_scalar_rules[Py_GE] = False
# ----------------------------------------------------------------------


def _make_nan_func(func_name, doc):
def _make_nan_func(func_name: str, doc: str):
def f(*args, **kwargs):
return np.nan
f.__name__ = func_name
f.__doc__ = doc
return f


def _make_nat_func(func_name, doc):
def _make_nat_func(func_name: str, doc: str):
def f(*args, **kwargs):
return c_NaT
f.__name__ = func_name
f.__doc__ = doc
return f


def _make_error_func(func_name, cls):
def _make_error_func(func_name: str, cls):
def f(*args, **kwargs):
raise ValueError(f"NaTType does not support {func_name}")

Expand Down Expand Up @@ -282,31 +282,31 @@ cdef class _NaT(datetime):
return NPY_NAT

@property
def is_leap_year(self):
def is_leap_year(self) -> bool:
return False

@property
def is_month_start(self):
def is_month_start(self) -> bool:
return False

@property
def is_quarter_start(self):
def is_quarter_start(self) -> bool:
return False

@property
def is_year_start(self):
def is_year_start(self) -> bool:
return False

@property
def is_month_end(self):
def is_month_end(self) -> bool:
return False

@property
def is_quarter_end(self):
def is_quarter_end(self) -> bool:
return False

@property
def is_year_end(self):
def is_year_end(self) -> bool:
return False


Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import cython

from cpython.datetime cimport (
datetime,
tzinfo,
PyDate_Check,
PyDateTime_Check,
PyDateTime_IMPORT,
Expand Down Expand Up @@ -1417,7 +1418,7 @@ def extract_freq(ndarray[object] values):

@cython.wraparound(False)
@cython.boundscheck(False)
def dt64arr_to_periodarr(const int64_t[:] stamps, int freq, object tz):
def dt64arr_to_periodarr(const int64_t[:] stamps, int freq, tzinfo tz):
cdef:
Py_ssize_t n = len(stamps)
int64_t[:] result = np.empty(n, dtype=np.int64)
Expand Down
31 changes: 16 additions & 15 deletions pandas/_libs/tslibs/tzconversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cython
from cython import Py_ssize_t

from cpython.datetime cimport (
PyDateTime_IMPORT, PyDelta_Check, datetime, tzinfo)
PyDateTime_IMPORT, PyDelta_Check, datetime, timedelta, tzinfo)
PyDateTime_IMPORT

import pytz
Expand Down Expand Up @@ -421,23 +421,22 @@ cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc):
converted : ndarray[int64_t]
"""
cdef:
int64_t[:] converted, result
int64_t[:] converted
Py_ssize_t i, n = len(vals)
int64_t val

if not is_utc(tz):
if is_utc(tz):
converted = vals
elif is_tzlocal(tz):
converted = np.empty(n, dtype=np.int64)
if is_tzlocal(tz):
for i in range(n):
val = vals[i]
if val == NPY_NAT:
converted[i] = NPY_NAT
else:
converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc)
else:
converted = _tz_convert_dst(vals, tz, to_utc)
for i in range(n):
val = vals[i]
if val == NPY_NAT:
converted[i] = NPY_NAT
else:
converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc)
else:
converted = vals
converted = _tz_convert_dst(vals, tz, to_utc)

return converted

Expand Down Expand Up @@ -471,11 +470,12 @@ cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
npy_datetimestruct dts
datetime dt
int64_t delta
timedelta td

dt64_to_dtstruct(val, &dts)
dt = datetime(dts.year, dts.month, dts.day, dts.hour,
dts.min, dts.sec, dts.us)
# get_utcoffset (tz.utcoffset under the hood) only makes sense if datetime
# tz.utcoffset only makes sense if datetime
# is _wall time_, so if val is a UTC timestamp convert to wall time
if not to_utc:
dt = dt.replace(tzinfo=tzutc())
Expand All @@ -484,7 +484,8 @@ cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
if fold is not NULL:
fold[0] = dt.fold

return int(get_utcoffset(tz, dt).total_seconds()) * 1000000000
td = tz.utcoffset(dt)
return int(td.total_seconds() * 1_000_000_000)


cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=True,
Expand Down