Skip to content

Commit b3ca3c0

Browse files
committed
Reviewer comments; remove cython decorators
Reviewer request to import NaT in parse_time_string
1 parent c765e26 commit b3ca3c0

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

pandas/_libs/tslib.pyx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ from khash cimport (
6666
kh_init_int64, kh_int64_t,
6767
kh_resize_int64, kh_get_int64)
6868

69-
from tslibs.parsing import parse_time_string as _parse_time_string
7069
from tslibs import parsing # noqa
7170
from tslibs.parsing import ( # noqa
7271
DateParseError,
@@ -75,6 +74,7 @@ from tslibs.parsing import ( # noqa
7574
_guess_datetime_format,
7675
NAT_SENTINEL,
7776
parse_datetime_string,
77+
parse_time_string,
7878
_does_string_look_like_datetime,
7979
parse_datetime_string_with_reso)
8080

@@ -5454,32 +5454,3 @@ cdef _calc_julian_from_U_or_W(int year, int week_of_year,
54545454

54555455
# def _strptime_time(data_string, format="%a %b %d %H:%M:%S %Y"):
54565456
# return _strptime(data_string, format)[0]
5457-
5458-
#----------------------------------------------------------------------
5459-
# Parsing
5460-
# Wrap tslibs.parsing functions to return `NaT` instead of `NAT_SENTINEL`
5461-
5462-
5463-
def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
5464-
"""
5465-
Try hard to parse datetime string, leveraging dateutil plus some extra
5466-
goodies like quarter recognition.
5467-
5468-
Parameters
5469-
----------
5470-
arg : compat.string_types
5471-
freq : str or DateOffset, default None
5472-
Helps with interpreting time string if supplied
5473-
dayfirst : bool, default None
5474-
If None uses default from print_config
5475-
yearfirst : bool, default None
5476-
If None uses default from print_config
5477-
5478-
Returns
5479-
-------
5480-
datetime, datetime/dateutil.parser._result, str
5481-
"""
5482-
res = _parse_time_string(arg, freq, dayfirst, yearfirst)
5483-
if isinstance(res, tuple) and res[0] is NAT_SENTINEL:
5484-
res = (NaT,) + res[1:]
5485-
return res

pandas/_libs/tslibs/parsing.pyx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,24 @@ def parse_datetime_string(date_string, freq=None, dayfirst=False,
107107

108108

109109
def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
110-
"""See tslib.parse_time_string.__doc__"""
110+
"""
111+
Try hard to parse datetime string, leveraging dateutil plus some extra
112+
goodies like quarter recognition.
113+
114+
Parameters
115+
----------
116+
arg : compat.string_types
117+
freq : str or DateOffset, default None
118+
Helps with interpreting time string if supplied
119+
dayfirst : bool, default None
120+
If None uses default from print_config
121+
yearfirst : bool, default None
122+
If None uses default from print_config
123+
124+
Returns
125+
-------
126+
datetime, datetime/dateutil.parser._result, str
127+
"""
111128
if not isinstance(arg, string_types):
112129
return arg
113130

@@ -121,9 +138,14 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
121138
from pandas.core.config import get_option
122139
yearfirst = get_option("display.date_yearfirst")
123140

124-
return parse_datetime_string_with_reso(arg, freq=freq,
125-
dayfirst=dayfirst,
126-
yearfirst=yearfirst)
141+
res = parse_datetime_string_with_reso(arg, freq=freq,
142+
dayfirst=dayfirst,
143+
yearfirst=yearfirst)
144+
if res[0] is NAT_SENTINEL:
145+
from pandas._libs.tslib import NaT
146+
res = (NaT,) + res[1:]
147+
return res
148+
127149

128150

129151
def parse_datetime_string_with_reso(date_string, freq=None, dayfirst=False,
@@ -349,10 +371,7 @@ def dateutil_parse(object timestr, object default, ignoretz=False,
349371

350372

351373
# The canonical place for this appears to be in frequencies.pyx.
352-
@cython.returns(object)
353-
@cython.locals(source=object, default=object)
354-
@cython.ccall
355-
def _get_rule_month(source, default='DEC'):
374+
cpdef object _get_rule_month(object source, object default='DEC'):
356375
"""
357376
Return starting month of given freq, default is December.
358377

0 commit comments

Comments
 (0)