Skip to content
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

update imports of DateParseError, remove unused imports from tslib #17713

Merged
merged 1 commit into from Sep 29, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 8 additions & 28 deletions pandas/_libs/tslib.pyx
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
# cython: profile=False

import warnings

cimport numpy as np
from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
float64_t,
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
float64_t, NPY_DATETIME, NPY_TIMEDELTA)
import numpy as np

import sys
Expand All @@ -16,12 +13,10 @@ from cpython cimport (
PyTypeObject,
PyFloat_Check,
PyComplex_Check,
PyLong_Check,
PyObject_RichCompareBool,
PyObject_RichCompare,
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE,
PyUnicode_Check,
PyUnicode_AsUTF8String)
PyUnicode_Check)

cdef extern from "Python.h":
cdef PyTypeObject *Py_TYPE(object)
Expand All @@ -38,7 +33,6 @@ from datetime cimport (
pandas_datetimestruct,
pandas_datetime_to_datetimestruct,
pandas_datetimestruct_to_datetime,
cmp_pandas_datetimestruct,
days_per_month_table,
get_datetime64_value,
get_timedelta64_value,
Expand Down Expand Up @@ -68,23 +62,12 @@ from khash cimport (
kh_resize_int64, kh_get_int64)

from .tslibs.parsing import parse_datetime_string
from .tslibs.parsing import DateParseError # noqa

cimport cython

import re
import time

# dateutil compat
from dateutil.tz import (tzoffset, tzlocal as _dateutil_tzlocal,
tzutc as _dateutil_tzutc,
tzstr as _dateutil_tzstr)

from dateutil.relativedelta import relativedelta
from dateutil.parser import DEFAULTPARSER

from pandas.compat import (parse_date, string_types, iteritems,
StringIO, callable)
from pandas.compat import iteritems, callable

import operator
import collections
Expand All @@ -97,9 +80,6 @@ import_array()
# import datetime C API
PyDateTime_IMPORT

# in numpy 1.7, will prob need the following:
# numpy_pydatetime_import

cdef int64_t NPY_NAT = util.get_nat()
iNaT = NPY_NAT

Expand Down Expand Up @@ -318,7 +298,7 @@ class Timestamp(_Timestamp):
tz : string / timezone object, default None
Timezone to localize to
"""
if isinstance(tz, string_types):
if util.is_string_object(tz):
tz = maybe_get_tz(tz)
return cls(datetime.now(tz))

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

kwargs = dict([ (k, _to_py_int_float(v))
for k, v in iteritems(kwargs) ])
kwargs = dict([(k, _to_py_int_float(v))
for k, v in iteritems(kwargs)])

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

if isinstance(ambiguous, string_types):
if util.is_string_object(ambiguous):
if ambiguous == 'infer':
infer_dst = True
elif ambiguous == 'NaT':
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Expand Up @@ -8,6 +8,7 @@
from pandas._libs.tslibs import parsing
from pandas._libs.tslibs.parsing import ( # noqa
parse_time_string,
DateParseError,
_format_is_iso,
_guess_datetime_format)

Expand Down Expand Up @@ -561,7 +562,6 @@ def calc_with_mask(carg, mask):
return None


DateParseError = tslib.DateParseError
normalize_date = tslib.normalize_date

# Fixed time formats for time parsing
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/datetimes/test_tools.py
Expand Up @@ -1335,13 +1335,13 @@ def test_parsers_monthfreq(self):
def test_parsers_quarterly_with_freq(self):
msg = ('Incorrect quarterly string is given, quarter '
'must be between 1 and 4: 2013Q5')
with tm.assert_raises_regex(tslib.DateParseError, msg):
with tm.assert_raises_regex(parsing.DateParseError, msg):
tools.parse_time_string('2013Q5')

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

cases = {('2013Q2', None): datetime(2013, 4, 1),
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/scalar/test_period.py
Expand Up @@ -11,6 +11,7 @@
from pandas.compat.numpy import np_datetime64_compat

from pandas._libs import tslib, period as libperiod
from pandas._libs.tslibs.parsing import DateParseError
from pandas import Period, Timestamp, offsets
from pandas.tseries.frequencies import DAYS, MONTHS

Expand Down Expand Up @@ -886,8 +887,8 @@ def test_constructor_infer_freq(self):

def test_badinput(self):
pytest.raises(ValueError, Period, '-2000', 'A')
pytest.raises(tslib.DateParseError, Period, '0', 'A')
pytest.raises(tslib.DateParseError, Period, '1/1/-2000', 'A')
pytest.raises(DateParseError, Period, '0', 'A')
pytest.raises(DateParseError, Period, '1/1/-2000', 'A')

def test_multiples(self):
result1 = Period('1989', freq='2A')
Expand Down