Skip to content

TYP: type unit as str #35099

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 1 commit into from
Jul 6, 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
6 changes: 3 additions & 3 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ def format_array_from_datetime(

def array_with_unit_to_datetime(
ndarray values,
object unit,
str errors='coerce'
str unit,
str errors="coerce"
):
"""
Convert the ndarray to datetime according to the time unit.
Expand All @@ -384,7 +384,7 @@ def array_with_unit_to_datetime(
----------
values : ndarray of object
Date-like objects to convert.
unit : object
unit : str
Time unit to use during conversion.
errors : str, default 'raise'
Error behavior when parsing.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/conversion.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cdef class _TSObject:
bint fold


cdef convert_to_tsobject(object ts, tzinfo tz, object unit,
cdef convert_to_tsobject(object ts, tzinfo tz, str unit,
bint dayfirst, bint yearfirst,
int32_t nanos=*)

Expand Down
20 changes: 16 additions & 4 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ TD64NS_DTYPE = np.dtype('m8[ns]')
# Unit Conversion Helpers

cdef inline int64_t cast_from_unit(object ts, str unit) except? -1:
""" return a casting of the unit represented to nanoseconds
round the fractional part of a float to our precision, p """
"""
Return a casting of the unit represented to nanoseconds
round the fractional part of a float to our precision, p.
Parameters
----------
ts : int, float, or None
unit : str
Returns
-------
int64_t
"""
cdef:
int64_t m
int p
Expand Down Expand Up @@ -307,7 +318,7 @@ cdef class _TSObject:
return self.value


cdef convert_to_tsobject(object ts, tzinfo tz, object unit,
cdef convert_to_tsobject(object ts, tzinfo tz, str unit,
bint dayfirst, bint yearfirst, int32_t nanos=0):
"""
Extract datetime and int64 from any of:
Expand Down Expand Up @@ -497,7 +508,7 @@ cdef _TSObject _create_tsobject_tz_using_offset(npy_datetimestruct dts,
return obj


cdef _TSObject _convert_str_to_tsobject(object ts, tzinfo tz, object unit,
cdef _TSObject _convert_str_to_tsobject(object ts, tzinfo tz, str unit,
bint dayfirst=False,
bint yearfirst=False):
"""
Expand All @@ -513,6 +524,7 @@ cdef _TSObject _convert_str_to_tsobject(object ts, tzinfo tz, object unit,
Value to be converted to _TSObject
tz : tzinfo or None
timezone for the timezone-aware output
unit : str or None
dayfirst : bool, default False
When parsing an ambiguous date string, interpret e.g. "3/4/1975" as
April 3, as opposed to the standard US interpretation March 4.
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from numpy cimport int64_t

# Exposed for tslib, not intended for outside use.
cpdef int64_t delta_to_nanoseconds(delta) except? -1
cdef convert_to_timedelta64(object ts, object unit)
cdef convert_to_timedelta64(object ts, str unit)
cdef bint is_any_td_scalar(object obj)


Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ cpdef int64_t delta_to_nanoseconds(delta) except? -1:
raise TypeError(type(delta))


cdef convert_to_timedelta64(object ts, object unit):
cdef convert_to_timedelta64(object ts, str unit):
"""
Convert an incoming object to a timedelta64 if possible.
Before calling, unit must be standardized to avoid repeated unit conversion
Expand Down Expand Up @@ -218,7 +218,7 @@ cdef convert_to_timedelta64(object ts, object unit):

@cython.boundscheck(False)
@cython.wraparound(False)
def array_to_timedelta64(object[:] values, unit=None, errors='raise'):
def array_to_timedelta64(object[:] values, str unit=None, str errors="raise"):
"""
Convert an ndarray to an array of timedeltas. If errors == 'coerce',
coerce non-convertible objects to NaT. Otherwise, raise.
Expand Down Expand Up @@ -470,7 +470,7 @@ cdef inline timedelta_from_spec(object number, object frac, object unit):
return cast_from_unit(float(n), unit)


cpdef inline str parse_timedelta_unit(object unit):
cpdef inline str parse_timedelta_unit(str unit):
"""
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ class Timestamp(_Timestamp):
nanosecond = hour
tz = minute
freq = None
unit = None

if getattr(ts_input, 'tzinfo', None) is not None and tz is not None:
raise ValueError("Cannot pass a datetime or Timestamp with tzinfo with "
Expand Down