Skip to content

Commit 03b5cca

Browse files
jbrockmendelNo-Stream
authored andcommitted
update imports of DateParseError, remove unused imports from tslib (pandas-dev#17713)
See pandas-dev#17652
1 parent 6dd73c1 commit 03b5cca

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

pandas/_libs/tslib.pyx

+8-28
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# cython: profile=False
33

4-
import warnings
5-
64
cimport numpy as np
75
from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
8-
float64_t,
9-
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
6+
float64_t, NPY_DATETIME, NPY_TIMEDELTA)
107
import numpy as np
118

129
import sys
@@ -16,12 +13,10 @@ from cpython cimport (
1613
PyTypeObject,
1714
PyFloat_Check,
1815
PyComplex_Check,
19-
PyLong_Check,
2016
PyObject_RichCompareBool,
2117
PyObject_RichCompare,
2218
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE,
23-
PyUnicode_Check,
24-
PyUnicode_AsUTF8String)
19+
PyUnicode_Check)
2520

2621
cdef extern from "Python.h":
2722
cdef PyTypeObject *Py_TYPE(object)
@@ -38,7 +33,6 @@ from datetime cimport (
3833
pandas_datetimestruct,
3934
pandas_datetime_to_datetimestruct,
4035
pandas_datetimestruct_to_datetime,
41-
cmp_pandas_datetimestruct,
4236
days_per_month_table,
4337
get_datetime64_value,
4438
get_timedelta64_value,
@@ -68,23 +62,12 @@ from khash cimport (
6862
kh_resize_int64, kh_get_int64)
6963

7064
from .tslibs.parsing import parse_datetime_string
71-
from .tslibs.parsing import DateParseError # noqa
7265

7366
cimport cython
7467

75-
import re
7668
import time
7769

78-
# dateutil compat
79-
from dateutil.tz import (tzoffset, tzlocal as _dateutil_tzlocal,
80-
tzutc as _dateutil_tzutc,
81-
tzstr as _dateutil_tzstr)
82-
83-
from dateutil.relativedelta import relativedelta
84-
from dateutil.parser import DEFAULTPARSER
85-
86-
from pandas.compat import (parse_date, string_types, iteritems,
87-
StringIO, callable)
70+
from pandas.compat import iteritems, callable
8871

8972
import operator
9073
import collections
@@ -97,9 +80,6 @@ import_array()
9780
# import datetime C API
9881
PyDateTime_IMPORT
9982

100-
# in numpy 1.7, will prob need the following:
101-
# numpy_pydatetime_import
102-
10383
cdef int64_t NPY_NAT = util.get_nat()
10484
iNaT = NPY_NAT
10585

@@ -318,7 +298,7 @@ class Timestamp(_Timestamp):
318298
tz : string / timezone object, default None
319299
Timezone to localize to
320300
"""
321-
if isinstance(tz, string_types):
301+
if util.is_string_object(tz):
322302
tz = maybe_get_tz(tz)
323303
return cls(datetime.now(tz))
324304

@@ -613,7 +593,7 @@ class Timestamp(_Timestamp):
613593
if self.tzinfo is None:
614594
# tz naive, localize
615595
tz = maybe_get_tz(tz)
616-
if not isinstance(ambiguous, string_types):
596+
if not util.is_string_object(ambiguous):
617597
ambiguous = [ambiguous]
618598
value = tz_localize_to_utc(np.array([self.value], dtype='i8'), tz,
619599
ambiguous=ambiguous, errors=errors)[0]
@@ -2426,8 +2406,8 @@ class Timedelta(_Timedelta):
24262406
raise TypeError(
24272407
"Invalid type {0}. Must be int or float.".format(type(v)))
24282408

2429-
kwargs = dict([ (k, _to_py_int_float(v))
2430-
for k, v in iteritems(kwargs) ])
2409+
kwargs = dict([(k, _to_py_int_float(v))
2410+
for k, v in iteritems(kwargs)])
24312411

24322412
try:
24332413
nano = kwargs.pop('nanoseconds', 0)
@@ -3682,7 +3662,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
36823662
result[i] = v - delta
36833663
return result
36843664

3685-
if isinstance(ambiguous, string_types):
3665+
if util.is_string_object(ambiguous):
36863666
if ambiguous == 'infer':
36873667
infer_dst = True
36883668
elif ambiguous == 'NaT':

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas._libs.tslibs import parsing
99
from pandas._libs.tslibs.parsing import ( # noqa
1010
parse_time_string,
11+
DateParseError,
1112
_format_is_iso,
1213
_guess_datetime_format)
1314

@@ -561,7 +562,6 @@ def calc_with_mask(carg, mask):
561562
return None
562563

563564

564-
DateParseError = tslib.DateParseError
565565
normalize_date = tslib.normalize_date
566566

567567
# Fixed time formats for time parsing

pandas/tests/indexes/datetimes/test_tools.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1335,13 +1335,13 @@ def test_parsers_monthfreq(self):
13351335
def test_parsers_quarterly_with_freq(self):
13361336
msg = ('Incorrect quarterly string is given, quarter '
13371337
'must be between 1 and 4: 2013Q5')
1338-
with tm.assert_raises_regex(tslib.DateParseError, msg):
1338+
with tm.assert_raises_regex(parsing.DateParseError, msg):
13391339
tools.parse_time_string('2013Q5')
13401340

13411341
# GH 5418
13421342
msg = ('Unable to retrieve month information from given freq: '
13431343
'INVLD-L-DEC-SAT')
1344-
with tm.assert_raises_regex(tslib.DateParseError, msg):
1344+
with tm.assert_raises_regex(parsing.DateParseError, msg):
13451345
tools.parse_time_string('2013Q1', freq='INVLD-L-DEC-SAT')
13461346

13471347
cases = {('2013Q2', None): datetime(2013, 4, 1),

pandas/tests/scalar/test_period.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas.compat.numpy import np_datetime64_compat
1212

1313
from pandas._libs import tslib, period as libperiod
14+
from pandas._libs.tslibs.parsing import DateParseError
1415
from pandas import Period, Timestamp, offsets
1516
from pandas.tseries.frequencies import DAYS, MONTHS
1617

@@ -886,8 +887,8 @@ def test_constructor_infer_freq(self):
886887

887888
def test_badinput(self):
888889
pytest.raises(ValueError, Period, '-2000', 'A')
889-
pytest.raises(tslib.DateParseError, Period, '0', 'A')
890-
pytest.raises(tslib.DateParseError, Period, '1/1/-2000', 'A')
890+
pytest.raises(DateParseError, Period, '0', 'A')
891+
pytest.raises(DateParseError, Period, '1/1/-2000', 'A')
891892

892893
def test_multiples(self):
893894
result1 = Period('1989', freq='2A')

0 commit comments

Comments
 (0)