diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index 6163705878250f..70b6b1e4396916 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -1,6 +1,7 @@ """ test with the TimeGrouper / grouping with datetimes """ import pytest +import pytz from datetime import datetime import numpy as np @@ -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 diff --git a/pandas/tests/indexes/datetimes/test_astype.py b/pandas/tests/indexes/datetimes/test_astype.py index 4727237960b78e..46be24b90faae4 100644 --- a/pandas/tests/indexes/datetimes/test_astype.py +++ b/pandas/tests/indexes/datetimes/test_astype.py @@ -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, @@ -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) @@ -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) @@ -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) @@ -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() @@ -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')) @@ -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') diff --git a/pandas/tests/indexes/datetimes/test_construction.py b/pandas/tests/indexes/datetimes/test_construction.py index 507703af5503be..cf896b06130a24 100644 --- a/pandas/tests/indexes/datetimes/test_construction.py +++ b/pandas/tests/indexes/datetimes/test_construction.py @@ -1,5 +1,6 @@ import pytest +import pytz import numpy as np from datetime import timedelta @@ -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) @@ -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', diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 7d3e907df151b4..62686b356dc302 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -6,6 +6,7 @@ import pytest import numpy as np +from pytz import timezone from datetime import datetime, timedelta, time import pandas as pd @@ -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)) @@ -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))), @@ -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 diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index b80573954fb340..6cba7e17abf8e8 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -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 @@ -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): diff --git a/pandas/tests/indexes/datetimes/test_indexing.py b/pandas/tests/indexes/datetimes/test_indexing.py index 18e61eddcfc4de..4ef5cc5499f4db 100644 --- a/pandas/tests/indexes/datetimes/test_indexing.py +++ b/pandas/tests/indexes/datetimes/test_indexing.py @@ -1,5 +1,6 @@ import pytest +import pytz import numpy as np import pandas as pd import pandas.util.testing as tm @@ -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): diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index 7592dda54231d4..f33cdf88007914 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -1,4 +1,6 @@ +import pytz import pytest +import dateutil import warnings import numpy as np from datetime import timedelta @@ -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): @@ -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): diff --git a/pandas/tests/indexes/datetimes/test_setops.py b/pandas/tests/indexes/datetimes/test_setops.py index ba279ffd7fd62f..5af73d3081d1ce 100644 --- a/pandas/tests/indexes/datetimes/test_setops.py +++ b/pandas/tests/indexes/datetimes/test_setops.py @@ -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') @@ -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') diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index a6f89df5f98274..61f7ac8abaf094 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -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 @@ -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)), @@ -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 @@ -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: @@ -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))} @@ -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) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 168ac21d6b6c8e..4431108a55963d 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -7,6 +7,8 @@ from __future__ import print_function import re +import pytz +import dateutil import itertools from operator import methodcaller import os @@ -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)) @@ -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) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index b008376309f997..662f06dbb725e2 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -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 @@ -397,7 +399,6 @@ 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() @@ -405,7 +406,6 @@ def test_encodeTimeConversion_pytz(self): 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() diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index c4f22a3e352c96..873bb20b3bba9a 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -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. diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index bf5d2574dab2f6..7486c32f57fdb8 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -1,5 +1,6 @@ from warnings import catch_warnings +import dateutil import numpy as np from numpy.random import randn @@ -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()), diff --git a/pandas/tests/scalar/test_period.py b/pandas/tests/scalar/test_period.py index c946d5bb410585..931d6b2b8f1f09 100644 --- a/pandas/tests/scalar/test_period.py +++ b/pandas/tests/scalar/test_period.py @@ -1,5 +1,6 @@ import pytest +import pytz import numpy as np from datetime import datetime, date, timedelta @@ -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) diff --git a/pandas/tests/scalar/test_timestamp.py b/pandas/tests/scalar/test_timestamp.py index 12a32060716d79..7cd1a7db0f9fe9 100644 --- a/pandas/tests/scalar/test_timestamp.py +++ b/pandas/tests/scalar/test_timestamp.py @@ -1,12 +1,18 @@ """ test the scalar Timestamp """ import sys +import pytz import pytest +import dateutil import operator import calendar import numpy as np + +from dateutil.tz import tzutc +from pytz import timezone, utc from datetime import datetime, timedelta from distutils.version import LooseVersion +from pytz.exceptions import AmbiguousTimeError, NonExistentTimeError import pandas.util.testing as tm from pandas.tseries import offsets, frequencies @@ -44,9 +50,6 @@ def test_constructor(self): Timestamp('2014-07-01 09:00:00.000000005'), base_expected + 5)] - pytz = pytest.importorskip("pytz") - pytest.importorskip("dateutil") - import dateutil timezones = [(None, 0), ('UTC', 0), (pytz.utc, 0), ('Asia/Tokyo', 9), ('US/Eastern', -4), ('dateutil/US/Pacific', -7), (pytz.FixedOffset(-180), -3), @@ -99,9 +102,6 @@ def test_constructor_with_stringoffset(self): ('2014-07-01 11:00:00.000008000+02:00', base_expected + 8000), ('2014-07-01 11:00:00.000000005+02:00', base_expected + 5)] - pytz = pytest.importorskip("pytz") - pytest.importorskip("dateutil") - import dateutil timezones = [(None, 0), ('UTC', 0), (pytz.utc, 0), ('Asia/Tokyo', 9), ('US/Eastern', -4), ('dateutil/US/Pacific', -7), (pytz.FixedOffset(-180), -3), @@ -272,9 +272,6 @@ def test_conversion(self): assert result.dtype == expected.dtype def test_repr(self): - pytz = pytest.importorskip("pytz") # noqa - dateutil = pytest.importorskip("dateutil") - dates = ['2014-03-07', '2014-01-01 09:00', '2014-01-01 00:00:00.000000001'] @@ -327,7 +324,6 @@ def test_repr(self): # This can cause the tz field to be populated, but it's redundant to # include this information in the date-string. - pytest.importorskip("pytz") date_with_utc_offset = Timestamp('2014-03-13 00:00:00-0400', tz=None) assert '2014-03-13 00:00:00-0400' in repr(date_with_utc_offset) assert 'tzoffset' not in repr(date_with_utc_offset) @@ -395,8 +391,7 @@ def test_tz_localize_ambiguous(self): Timestamp('2011-01-01').tz_convert('Asia/Tokyo') def test_tz_localize_nonexistent(self): - # See issue 13057 - from pytz.exceptions import NonExistentTimeError + # see gh-13057 times = ['2015-03-08 02:00', '2015-03-08 02:30', '2015-03-29 02:00', '2015-03-29 02:30'] timezones = ['US/Eastern', 'US/Pacific', @@ -410,8 +405,7 @@ def test_tz_localize_nonexistent(self): assert ts.tz_localize(tz, errors='coerce') is NaT def test_tz_localize_errors_ambiguous(self): - # See issue 13057 - from pytz.exceptions import AmbiguousTimeError + # see gh-13057 ts = Timestamp('2015-11-1 01:00') pytest.raises(AmbiguousTimeError, ts.tz_localize, 'US/Pacific', errors='coerce') @@ -705,9 +699,6 @@ def _check_round(freq, expected): stamp.round('foo') def test_class_ops_pytz(self): - pytest.importorskip("pytz") - from pytz import timezone - def compare(x, y): assert (int(Timestamp(x).value / 1e9) == int(Timestamp(y).value / 1e9)) @@ -728,9 +719,6 @@ def compare(x, y): datetime.combine(date_component, time_component)) def test_class_ops_dateutil(self): - pytest.importorskip("dateutil") - from dateutil.tz import tzutc - def compare(x, y): assert (int(np.round(Timestamp(x).value / 1e9)) == int(np.round(Timestamp(y).value / 1e9))) @@ -906,8 +894,7 @@ def test_compare_invalid(self): tm.assert_series_equal(a / b, 1 / (b / a)) def test_cant_compare_tz_naive_w_aware(self): - pytest.importorskip("pytz") - # #1404 + # see gh-1404 a = Timestamp('3/12/2012') b = Timestamp('3/12/2012', tz='utc') @@ -928,9 +915,7 @@ def test_cant_compare_tz_naive_w_aware(self): assert not a.to_pydatetime() == b def test_cant_compare_tz_naive_w_aware_explicit_pytz(self): - pytest.importorskip("pytz") - from pytz import utc - # #1404 + # see gh-1404 a = Timestamp('3/12/2012') b = Timestamp('3/12/2012', tz=utc) @@ -951,12 +936,9 @@ def test_cant_compare_tz_naive_w_aware_explicit_pytz(self): assert not a.to_pydatetime() == b def test_cant_compare_tz_naive_w_aware_dateutil(self): - pytest.importorskip("dateutil") - from dateutil.tz import tzutc - utc = tzutc() - # #1404 + # see gh-1404 a = Timestamp('3/12/2012') - b = Timestamp('3/12/2012', tz=utc) + b = Timestamp('3/12/2012', tz=tzutc()) pytest.raises(Exception, a.__eq__, b) pytest.raises(Exception, a.__ne__, b) @@ -1278,7 +1260,6 @@ def test_compare_hour13(self): class TestTimeSeries(object): def test_timestamp_to_datetime(self): - pytest.importorskip("pytz") rng = date_range('20090415', '20090519', tz='US/Eastern') stamp = rng[0] @@ -1287,7 +1268,6 @@ def test_timestamp_to_datetime(self): assert stamp.tzinfo == dtval.tzinfo def test_timestamp_to_datetime_dateutil(self): - pytest.importorskip("pytz") rng = date_range('20090415', '20090519', tz='dateutil/US/Eastern') stamp = rng[0] @@ -1296,7 +1276,6 @@ def test_timestamp_to_datetime_dateutil(self): assert stamp.tzinfo == dtval.tzinfo def test_timestamp_to_datetime_explicit_pytz(self): - pytz = pytest.importorskip("pytz") rng = date_range('20090415', '20090519', tz=pytz.timezone('US/Eastern')) @@ -1307,7 +1286,7 @@ def test_timestamp_to_datetime_explicit_pytz(self): def test_timestamp_to_datetime_explicit_dateutil(self): tm._skip_if_windows_python_3() - pytest.importorskip("dateutil") + from pandas._libs.tslib import _dateutil_gettz as gettz rng = date_range('20090415', '20090519', tz=gettz('US/Eastern')) diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index 2d19d8be868628..71ac00975af03d 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -246,9 +246,7 @@ def test_append_concat(self): assert rng1.append(rng2).name is None def test_append_concat_tz(self): - # GH 2938 - pytest.importorskip("pytz") - + # see gh-2938 rng = date_range('5/8/2012 1:45', periods=10, freq='5T', tz='US/Eastern') rng2 = date_range('5/8/2012 2:35', periods=10, freq='5T', @@ -270,7 +268,6 @@ def test_append_concat_tz(self): def test_append_concat_tz_explicit_pytz(self): # see gh-2938 - pytest.importorskip("pytz") from pytz import timezone as timezone rng = date_range('5/8/2012 1:45', periods=10, freq='5T', @@ -294,7 +291,6 @@ def test_append_concat_tz_explicit_pytz(self): def test_append_concat_tz_dateutil(self): # see gh-2938 - pytest.importorskip("dateutil") rng = date_range('5/8/2012 1:45', periods=10, freq='5T', tz='dateutil/US/Eastern') rng2 = date_range('5/8/2012 2:35', periods=10, freq='5T', diff --git a/pandas/tests/series/test_indexing.py b/pandas/tests/series/test_indexing.py index 4274ca44a2315b..6ded4d593a571d 100644 --- a/pandas/tests/series/test_indexing.py +++ b/pandas/tests/series/test_indexing.py @@ -338,9 +338,7 @@ def test_getitem_setitem_slice_integers(self): assert not (s[4:] == 0).any() def test_getitem_setitem_datetime_tz_pytz(self): - pytest.importorskip("pytz") from pytz import timezone as tz - from pandas import date_range N = 50 @@ -374,7 +372,6 @@ def test_getitem_setitem_datetime_tz_pytz(self): assert_series_equal(result, ts) def test_getitem_setitem_datetime_tz_dateutil(self): - pytest.importorskip("dateutil") from dateutil.tz import tzutc from pandas._libs.tslib import _dateutil_gettz as gettz diff --git a/pandas/tests/series/test_operators.py b/pandas/tests/series/test_operators.py index 20d70074efbf4f..2e400812e0331f 100644 --- a/pandas/tests/series/test_operators.py +++ b/pandas/tests/series/test_operators.py @@ -2,6 +2,7 @@ # pylint: disable-msg=E1101,W0612 import pytest +import pytz from collections import Iterable from datetime import datetime, timedelta @@ -726,7 +727,6 @@ def run_ops(ops, get_ser, test_ser): def test_sub_datetime_compat(self): # see gh-14088 - pytz = pytest.importorskip("pytz") s = Series([datetime(2016, 8, 23, 12, tzinfo=pytz.utc), pd.NaT]) dt = datetime(2016, 8, 22, 12, tzinfo=pytz.utc) exp = Series([Timedelta('1 days'), pd.NaT]) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 189ca08c75b56d..9d80190ae28137 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -4,6 +4,7 @@ import datetime import itertools import pytest +import pytz from numpy.random import randn import numpy as np @@ -68,8 +69,6 @@ def test_append(self): tm.assert_series_equal(result, self.frame['A']) def test_append_index(self): - pytz = pytest.importorskip("pytz") - idx1 = Index([1.1, 1.2, 1.3]) idx2 = pd.date_range('2011-01-01', freq='D', periods=3, tz='Asia/Tokyo') diff --git a/pandas/tests/test_resample.py b/pandas/tests/test_resample.py index 71050176f046d2..37e2fd0e9b188b 100644 --- a/pandas/tests/test_resample.py +++ b/pandas/tests/test_resample.py @@ -4,7 +4,9 @@ from datetime import datetime, timedelta from functools import partial +import pytz import pytest +import dateutil import numpy as np import pandas as pd @@ -2425,8 +2427,6 @@ def test_resample_incompat_freq(self): def test_with_local_timezone_pytz(self): # see gh-5430 - pytz = pytest.importorskip("pytz") - local_timezone = pytz.timezone('America/Los_Angeles') start = datetime(year=2013, month=11, day=1, hour=0, minute=0, @@ -2450,8 +2450,6 @@ def test_with_local_timezone_pytz(self): def test_with_local_timezone_dateutil(self): # see gh-5430 - dateutil = pytest.importorskip("dateutil") - local_timezone = 'dateutil/America/Los_Angeles' start = datetime(year=2013, month=11, day=1, hour=0, minute=0, diff --git a/pandas/tests/tseries/test_offsets.py b/pandas/tests/tseries/test_offsets.py index 29dc694c8da696..47b15a2b66fc46 100644 --- a/pandas/tests/tseries/test_offsets.py +++ b/pandas/tests/tseries/test_offsets.py @@ -148,8 +148,6 @@ def test_apply_out_of_range(self): assert isinstance(result, datetime) assert result.tzinfo is None - pytest.importorskip("pytz") - pytest.importorskip("dateutil") # Check tz is preserved for tz in self.timezones: t = Timestamp('20080101', tz=tz) @@ -285,9 +283,6 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, # test tz when input is datetime or Timestamp return - pytest.importorskip("pytz") - pytest.importorskip("dateutil") - for tz in self.timezones: expected_localize = expected.tz_localize(tz) tz_obj = tslib.maybe_get_tz(tz) @@ -468,7 +463,6 @@ def test_add(self): assert isinstance(result, Timestamp) assert result == expected - pytest.importorskip("pytz") for tz in self.timezones: expected_localize = expected.tz_localize(tz) result = Timestamp(dt, tz=tz) + offset_s diff --git a/pandas/tests/tseries/test_timezones.py b/pandas/tests/tseries/test_timezones.py index c7ab05d675bb6b..de6978d52968b0 100644 --- a/pandas/tests/tseries/test_timezones.py +++ b/pandas/tests/tseries/test_timezones.py @@ -1,10 +1,15 @@ # pylint: disable-msg=E1101,W0612 import pytest + import pytz +import dateutil import numpy as np + +from dateutil.parser import parse +from pytz import NonExistentTimeError from distutils.version import LooseVersion +from dateutil.tz import tzlocal, tzoffset from datetime import datetime, timedelta, tzinfo, date -from pytz import NonExistentTimeError import pandas.util.testing as tm import pandas.core.tools.datetimes as tools @@ -18,16 +23,6 @@ from pandas.util.testing import (assert_frame_equal, assert_series_equal, set_timezone) -try: - import pytz # noqa -except ImportError: - pass - -try: - import dateutil -except ImportError: - pass - class FixedOffset(tzinfo): """Fixed offset in minutes east from UTC.""" @@ -52,9 +47,6 @@ def dst(self, dt): class TestTimeZoneSupportPytz(object): - def setup_method(self, method): - pytest.importorskip("pytz") - def tz(self, tz): # Construct a timezone object from a string. Overridden in subclass to # parameterize tests. @@ -207,8 +199,6 @@ def test_timestamp_constructor_near_dst_boundary(self): assert result == expected def test_timestamp_to_datetime_tzoffset(self): - # tzoffset - from dateutil.tz import tzoffset tzinfo = tzoffset(None, 7200) expected = Timestamp('3/11/2012 04:00', tz=tzinfo) result = Timestamp(expected.to_pydatetime()) @@ -764,15 +754,12 @@ def test_convert_tz_aware_datetime_datetime(self): assert converted.tz is pytz.utc def test_to_datetime_utc(self): - from dateutil.parser import parse arr = np.array([parse('2012-06-13T01:39:00Z')], dtype=object) result = to_datetime(arr, utc=True) assert result.tz is pytz.utc def test_to_datetime_tzlocal(self): - from dateutil.parser import parse - from dateutil.tz import tzlocal dt = parse('2012-06-13T01:39:00Z') dt = dt.replace(tzinfo=tzlocal()) @@ -888,7 +875,6 @@ def test_frame_reset_index(self): assert xp == rs def test_dateutil_tzoffset_support(self): - from dateutil.tz import tzoffset values = [188.5, 328.25] tzinfo = tzoffset(None, 7200) index = [datetime(2012, 5, 11, 11, tzinfo=tzinfo), @@ -943,9 +929,6 @@ def test_datetimeindex_tz_nat(self): class TestTimeZoneSupportDateutil(TestTimeZoneSupportPytz): - def setup_method(self, method): - pytest.importorskip("dateutil") - def tz(self, tz): """ Construct a dateutil timezone. @@ -1196,9 +1179,6 @@ def test_cache_keys_are_distinct_for_pytz_vs_dateutil(self): class TestTimeZones(object): timezones = ['UTC', 'Asia/Tokyo', 'US/Eastern', 'dateutil/US/Pacific'] - def setup_method(self, method): - pytest.importorskip("pytz") - def test_replace(self): # GH 14621 # GH 7825 @@ -1243,8 +1223,6 @@ def f(): def test_ambiguous_compat(self): # validate that pytz and dateutil are compat for dst # when the transition happens - pytest.importorskip("dateutil") - pytest.importorskip("pytz") pytz_zone = 'Europe/London' dateutil_zone = 'dateutil/Europe/London' @@ -1636,7 +1614,6 @@ def test_normalize_tz(self): assert result.is_normalized assert not rng.is_normalized - from dateutil.tz import tzlocal rng = date_range('1/1/2000 9:30', periods=10, freq='D', tz=tzlocal()) result = rng.normalize() expected = date_range('1/1/2000', periods=10, freq='D', tz=tzlocal()) @@ -1646,9 +1623,7 @@ def test_normalize_tz(self): assert not rng.is_normalized def test_normalize_tz_local(self): - # GH 13459 - from dateutil.tz import tzlocal - + # see gh-13459 timezones = ['US/Pacific', 'US/Eastern', 'UTC', 'Asia/Kolkata', 'Asia/Shanghai', 'Australia/Canberra']