Skip to content

Commit

Permalink
Import dateutil and pytz without checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed May 7, 2017
1 parent cf3c10d commit 42ec6ff
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 148 deletions.
6 changes: 3 additions & 3 deletions pandas/tests/groupby/test_timegrouper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" test with the TimeGrouper / grouping with datetimes """

import pytest
import pytz

from datetime import datetime
import numpy as np
Expand Down Expand Up @@ -569,9 +570,8 @@ def test_groupby_with_timezone_selection(self):
tm.assert_series_equal(df1, df2)

def test_timezone_info(self):
# GH 11682
# Timezone info lost when broadcasting scalar datetime to DataFrame
pytz = pytest.importorskip("pytz")
# see gh-11682: Timezone info lost when broadcasting
# scalar datetime to DataFrame

df = pd.DataFrame({'a': [1], 'b': [datetime.now(pytz.utc)]})
assert df['b'][0].tzinfo == pytz.utc
Expand Down
18 changes: 4 additions & 14 deletions pandas/tests/indexes/datetimes/test_astype.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import pytest

import pytz
import dateutil
import numpy as np

from datetime import datetime
from dateutil.tz import tzlocal

import pandas as pd
import pandas.util.testing as tm
from pandas import (DatetimeIndex, date_range, Series, NaT, Index, Timestamp,
Expand Down Expand Up @@ -124,8 +128,6 @@ def test_astype_raises(self):
pytest.raises(ValueError, idx.astype, 'datetime64[D]')

def test_index_convert_to_datetime_array(self):
pytest.importorskip("pytz")

def _check_rng(rng):
converted = rng.to_pydatetime()
assert isinstance(converted, np.ndarray)
Expand All @@ -143,8 +145,6 @@ def _check_rng(rng):
_check_rng(rng_utc)

def test_index_convert_to_datetime_array_explicit_pytz(self):
pytz = pytest.importorskip("pytz")

def _check_rng(rng):
converted = rng.to_pydatetime()
assert isinstance(converted, np.ndarray)
Expand All @@ -163,8 +163,6 @@ def _check_rng(rng):
_check_rng(rng_utc)

def test_index_convert_to_datetime_array_dateutil(self):
dateutil = pytest.importorskip("dateutil")

def _check_rng(rng):
converted = rng.to_pydatetime()
assert isinstance(converted, np.ndarray)
Expand Down Expand Up @@ -207,8 +205,6 @@ def test_to_period_microsecond(self):
assert period[1] == Period('2007-01-01 10:11:13.789123Z', 'U')

def test_to_period_tz_pytz(self):
pytest.importorskip("pytz")
from dateutil.tz import tzlocal
from pytz import utc as UTC

xp = date_range('1/1/2000', '4/1/2000').to_period()
Expand Down Expand Up @@ -238,9 +234,6 @@ def test_to_period_tz_pytz(self):
tm.assert_index_equal(ts.to_period(), xp)

def test_to_period_tz_explicit_pytz(self):
pytz = pytest.importorskip("pytz")
from dateutil.tz import tzlocal

xp = date_range('1/1/2000', '4/1/2000').to_period()

ts = date_range('1/1/2000', '4/1/2000', tz=pytz.timezone('US/Eastern'))
Expand Down Expand Up @@ -268,9 +261,6 @@ def test_to_period_tz_explicit_pytz(self):
tm.assert_index_equal(ts.to_period(), xp)

def test_to_period_tz_dateutil(self):
dateutil = pytest.importorskip("dateutil")
from dateutil.tz import tzlocal

xp = date_range('1/1/2000', '4/1/2000').to_period()

ts = date_range('1/1/2000', '4/1/2000', tz='dateutil/US/Eastern')
Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/indexes/datetimes/test_construction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import pytz
import numpy as np
from datetime import timedelta

Expand Down Expand Up @@ -350,10 +351,7 @@ def test_constructor_coverage(self):
pytest.raises(ValueError, DatetimeIndex, periods=10, freq='D')

def test_constructor_datetime64_tzformat(self):
# see gh-6572
pytz = pytest.importorskip("pytz")

# ISO 8601 format results in pytz.FixedOffset
# see gh-6572: ISO 8601 format results in pytz.FixedOffset
for freq in ['AS', 'W-SUN']:
idx = date_range('2013-01-01T00:00:00-05:00',
'2016-01-01T23:59:59-05:00', freq=freq)
Expand All @@ -376,8 +374,6 @@ def test_constructor_datetime64_tzformat(self):
tz='Asia/Tokyo')
tm.assert_numpy_array_equal(idx.asi8, expected_i8.asi8)

pytest.importorskip("dateutil")

# Non ISO 8601 format results in dateutil.tz.tzoffset
for freq in ['AS', 'W-SUN']:
idx = date_range('2013/1/1 0:00:00-5:00', '2016/1/1 23:59:59-5:00',
Expand Down
10 changes: 2 additions & 8 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

import numpy as np
from pytz import timezone
from datetime import datetime, timedelta, time

import pandas as pd
Expand Down Expand Up @@ -299,10 +300,7 @@ def test_range_bug(self):
tm.assert_index_equal(result, DatetimeIndex(exp_values))

def test_range_tz_pytz(self):
# GH 2906
pytest.importorskip("pytz")
from pytz import timezone

# see gh-2906
tz = timezone('US/Eastern')
start = tz.localize(datetime(2011, 1, 1))
end = tz.localize(datetime(2011, 1, 3))
Expand All @@ -323,9 +321,6 @@ def test_range_tz_pytz(self):
assert dr[2] == end

def test_range_tz_dst_straddle_pytz(self):

pytest.importorskip("pytz")
from pytz import timezone
tz = timezone('US/Eastern')
dates = [(tz.localize(datetime(2014, 3, 6)),
tz.localize(datetime(2014, 3, 12))),
Expand All @@ -350,7 +345,6 @@ def test_range_tz_dst_straddle_pytz(self):

def test_range_tz_dateutil(self):
# see gh-2906
pytest.importorskip("dateutil")

# Use maybe_get_tz to fix filename in tz under dateutil.
from pandas._libs.tslib import maybe_get_tz
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from datetime import date, timedelta, time

import dateutil
import pandas as pd
import pandas.util.testing as tm
from pandas.compat import lrange
Expand Down Expand Up @@ -363,9 +364,7 @@ def test_map(self):
tm.assert_index_equal(result, exp)

def test_iteration_preserves_tz(self):

# see gh-8890
dateutil = pytest.importorskip("dateutil")
index = date_range("2012-01-01", periods=3, freq='H', tz='US/Eastern')

for i, ts in enumerate(index):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_indexing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import pytz
import numpy as np
import pandas as pd
import pandas.util.testing as tm
Expand Down Expand Up @@ -98,8 +99,6 @@ def test_insert(self):
assert result.freq is None

# see gh-7299
pytz = pytest.importorskip("pytz")

idx = date_range('1/1/2000', periods=3, freq='D', tz='Asia/Tokyo',
name='idx')
with pytest.raises(ValueError):
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/indexes/datetimes/test_ops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytz
import pytest
import dateutil
import warnings
import numpy as np
from datetime import timedelta
Expand Down Expand Up @@ -1177,11 +1179,9 @@ def test_summary(self):
self.rng[2:2].summary()

def test_summary_pytz(self):
pytz = pytest.importorskip("pytz")
bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc).summary()

def test_summary_dateutil(self):
dateutil = pytest.importorskip("dateutil")
bdate_range('1/1/2005', '1/1/2009', tz=dateutil.tz.tzutc()).summary()

def test_equals(self):
Expand Down Expand Up @@ -1277,11 +1277,9 @@ def test_summary(self):
self.rng[2:2].summary()

def test_summary_pytz(self):
pytz = pytest.importorskip("pytz")
cdate_range('1/1/2005', '1/1/2009', tz=pytz.utc).summary()

def test_summary_dateutil(self):
dateutil = pytest.importorskip("dateutil")
cdate_range('1/1/2005', '1/1/2009', tz=dateutil.tz.tzutc()).summary()

def test_equals(self):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ def test_intersection_bug(self):
tm.assert_index_equal(result, b)

def test_month_range_union_tz_pytz(self):
pytest.importorskip("pytz")
from pytz import timezone
tz = timezone('US/Eastern')

Expand All @@ -326,7 +325,7 @@ def test_month_range_union_tz_pytz(self):

def test_month_range_union_tz_dateutil(self):
tm._skip_if_windows_python_3()
pytest.importorskip("dateutil")

from pandas._libs.tslib import _dateutil_gettz as timezone
tz = timezone('US/Eastern')

Expand Down
12 changes: 3 additions & 9 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
""" test to_datetime """

import sys
import pytz
import pytest
import locale
import calendar
import dateutil
import numpy as np
from dateutil.parser import parse
from datetime import datetime, date, time
from distutils.version import LooseVersion

Expand Down Expand Up @@ -244,10 +247,7 @@ def test_to_datetime_tz(self):
pytest.raises(ValueError, lambda: pd.to_datetime(arr))

def test_to_datetime_tz_pytz(self):

# see gh-8260
pytz = pytest.importorskip("pytz")

us_eastern = pytz.timezone('US/Eastern')
arr = np.array([us_eastern.localize(datetime(year=2000, month=1, day=1,
hour=3, minute=0)),
Expand Down Expand Up @@ -1163,7 +1163,6 @@ def test_parsers_dayfirst_yearfirst(self):
# 2.5.2 20/12/21 [dayfirst=1, yearfirst=0] -> 2021-12-20 00:00:00
# 2.5.3 20/12/21 [dayfirst=1, yearfirst=0] -> 2021-12-20 00:00:00

dateutil = pytest.importorskip("dateutil")
is_lt_253 = dateutil.__version__ < LooseVersion('2.5.3')

# str : dayfirst, yearfirst, expected
Expand All @@ -1184,7 +1183,6 @@ def test_parsers_dayfirst_yearfirst(self):
(True, True,
datetime(2020, 12, 21))]}

from dateutil.parser import parse
for date_str, values in compat.iteritems(cases):
for dayfirst, yearfirst, expected in values:

Expand Down Expand Up @@ -1218,9 +1216,6 @@ def test_parsers_dayfirst_yearfirst(self):
assert result4 == expected

def test_parsers_timestring(self):
pytest.importorskip("dateutil")
from dateutil.parser import parse

# must be the same as dateutil result
cases = {'10:15': (parse('10:15'), datetime(1, 1, 1, 10, 15)),
'9:05': (parse('9:05'), datetime(1, 1, 1, 9, 5))}
Expand Down Expand Up @@ -1362,7 +1357,6 @@ def test_parsers_iso8601(self):
class TestArrayToDatetime(object):

def test_try_parse_dates(self):
from dateutil.parser import parse
arr = np.array(['5/1/2000', '6/1/2000', '7/1/2000'], dtype=object)

result = lib.try_parse_dates(arr, dayfirst=True)
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from __future__ import print_function
import re

import pytz
import dateutil
import itertools
from operator import methodcaller
import os
Expand Down Expand Up @@ -2506,10 +2508,6 @@ def test_no_tz(self):
assert str(ts_nanos_micros) == "1970-01-01 00:00:00.000001200"

def test_tz_pytz(self):
pytest.importorskip("pytz")

import pytz

dt_date = datetime(2013, 1, 2, tzinfo=pytz.utc)
assert str(dt_date) == str(Timestamp(dt_date))

Expand All @@ -2520,7 +2518,6 @@ def test_tz_pytz(self):
assert str(dt_datetime_us) == str(Timestamp(dt_datetime_us))

def test_tz_dateutil(self):
dateutil = pytest.importorskip("dateutil")
utc = dateutil.tz.tzutc()

dt_date = datetime(2013, 1, 2, tzinfo=utc)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
except ImportError:
import simplejson as json
import math
import pytz
import pytest
import time
import datetime
import calendar
import re
import decimal
import dateutil
from functools import partial
from pandas.compat import range, zip, StringIO, u
import pandas._libs.json as ujson
Expand Down Expand Up @@ -397,15 +399,13 @@ def test_encodeTimeConversion(self):

def test_encodeTimeConversion_pytz(self):
# see gh-11473: to_json segfaults with timezone-aware datetimes
pytz = pytest.importorskip("pytz")
test = datetime.time(10, 12, 15, 343243, pytz.utc)
output = ujson.encode(test)
expected = '"%s"' % test.isoformat()
assert expected == output

def test_encodeTimeConversion_dateutil(self):
# see gh-11473: to_json segfaults with timezone-aware datetimes
dateutil = pytest.importorskip("dateutil")
test = datetime.time(10, 12, 15, 343243, dateutil.tz.tzutc())
output = ujson.encode(test)
expected = '"%s"' % test.isoformat()
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5243,7 +5243,6 @@ def _compare_with_tz(self, a, b):
def test_append_with_timezones_dateutil(self):

from datetime import timedelta
pytest.importorskip("dateutil")

# use maybe_get_tz instead of dateutil.tz.gettz to handle the windows
# filename issues.
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/reshape/test_concat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from warnings import catch_warnings

import dateutil
import numpy as np
from numpy.random import randn

Expand Down Expand Up @@ -1780,8 +1781,6 @@ def test_concat_tz_series_with_datetimelike(self):

def test_concat_tz_series_tzlocal(self):
# see gh-13583
dateutil = pytest.importorskip("dateutil")

x = [pd.Timestamp('2011-01-01', tz=dateutil.tz.tzlocal()),
pd.Timestamp('2011-02-01', tz=dateutil.tz.tzlocal())]
y = [pd.Timestamp('2012-01-01', tz=dateutil.tz.tzlocal()),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/test_period.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import pytz
import numpy as np
from datetime import datetime, date, timedelta

Expand Down Expand Up @@ -210,7 +211,6 @@ def test_period_cons_combined(self):
Period('2011-01', freq='1D1W')

def test_timestamp_tz_arg(self):
pytz = pytest.importorskip("pytz")
for case in ['Europe/Brussels', 'Asia/Tokyo', 'US/Pacific']:
p = Period('1/1/2005', freq='M').to_timestamp(tz=case)
exp = Timestamp('1/1/2005', tz='UTC').tz_convert(case)
Expand Down
Loading

0 comments on commit 42ec6ff

Please sign in to comment.