diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index a94865d8e9657..c89e3ddbfc5d0 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -22,7 +22,7 @@ from pandas.core.dtypes.common import is_datetime64_ns_dtype from pandas.util import testing as tm import pandas.util._test_decorators as td -from pandas.util.testing import assert_series_equal, _skip_if_has_locale +from pandas.util.testing import assert_series_equal from pandas import (isna, to_datetime, Timestamp, Series, DataFrame, Index, DatetimeIndex, NaT, date_range, compat) @@ -144,11 +144,10 @@ def test_to_datetime_format_time(self, cache): for s, format, dt in data: assert to_datetime(s, format=format, cache=cache) == dt + @td.skip_if_has_locale @pytest.mark.parametrize('cache', [True, False]) def test_to_datetime_with_non_exact(self, cache): # GH 10834 - tm._skip_if_has_locale() - # 8904 # exact kw if sys.version_info < (2, 7): @@ -830,11 +829,10 @@ def test_to_datetime_with_space_in_series(self, cache): result_ignore = to_datetime(s, errors='ignore', cache=cache) tm.assert_series_equal(result_ignore, s) + @td.skip_if_has_locale @pytest.mark.parametrize('cache', [True, False]) def test_to_datetime_with_apply(self, cache): # this is only locale tested with US/None locales - tm._skip_if_has_locale() - # GH 5195 # with a format and coerce a single item to_datetime fails td = Series(['May 04', 'Jun 02', 'Dec 11'], index=[1, 2, 3]) @@ -1023,9 +1021,9 @@ def test_dayfirst(self, cache): class TestGuessDatetimeFormat(object): + @td.skip_if_not_us_locale @is_dateutil_le_261 def test_guess_datetime_format_for_array(self): - tm._skip_if_not_us_locale() expected_format = '%Y-%m-%d %H:%M:%S.%f' dt_string = datetime(2011, 12, 30, 0, 0, 0).strftime(expected_format) @@ -1044,9 +1042,9 @@ def test_guess_datetime_format_for_array(self): [np.nan, np.nan, np.nan], dtype='O')) assert format_for_string_of_nans is None + @td.skip_if_not_us_locale @is_dateutil_gt_261 def test_guess_datetime_format_for_array_gt_261(self): - tm._skip_if_not_us_locale() expected_format = '%Y-%m-%d %H:%M:%S.%f' dt_string = datetime(2011, 12, 30, 0, 0, 0).strftime(expected_format) @@ -1393,9 +1391,9 @@ def test_parsers_timestring(self, cache): assert result4 == exp_now assert result5 == exp_now + @td.skip_if_has_locale def test_parsers_time(self): # GH11818 - _skip_if_has_locale() strings = ["14:15", "1415", "2:15pm", "0215pm", "14:15:00", "141500", "2:15:00pm", "021500pm", time(14, 15)] expected = time(14, 15) diff --git a/pandas/tests/scalar/test_parsing.py b/pandas/tests/scalar/test_parsing.py index 70961755ceec9..8ae858d791a97 100644 --- a/pandas/tests/scalar/test_parsing.py +++ b/pandas/tests/scalar/test_parsing.py @@ -6,6 +6,8 @@ import numpy as np import pytest from dateutil.parser import parse + +import pandas.util._test_decorators as td from pandas.conftest import is_dateutil_le_261, is_dateutil_gt_261 from pandas import compat from pandas.util import testing as tm @@ -66,6 +68,7 @@ def test_parsers_monthfreq(self): class TestGuessDatetimeFormat(object): + @td.skip_if_not_us_locale @is_dateutil_le_261 @pytest.mark.parametrize( "string, format", @@ -79,11 +82,10 @@ class TestGuessDatetimeFormat(object): '%Y-%m-%d %H:%M:%S.%f')]) def test_guess_datetime_format_with_parseable_formats( self, string, format): - tm._skip_if_not_us_locale() - result = parsing._guess_datetime_format(string) assert result == format + @td.skip_if_not_us_locale @is_dateutil_gt_261 @pytest.mark.parametrize( "string", @@ -92,8 +94,6 @@ def test_guess_datetime_format_with_parseable_formats( '2011-12-30 00:00:00.000000']) def test_guess_datetime_format_with_parseable_formats_gt_261( self, string): - tm._skip_if_not_us_locale() - result = parsing._guess_datetime_format(string) assert result is None @@ -118,6 +118,7 @@ def test_guess_datetime_format_with_dayfirst_gt_261(self, dayfirst): ambiguous_string, dayfirst=dayfirst) assert result is None + @td.skip_if_has_locale @is_dateutil_le_261 @pytest.mark.parametrize( "string, format", @@ -127,13 +128,10 @@ def test_guess_datetime_format_with_dayfirst_gt_261(self, dayfirst): ('30/Dec/2011 00:00:00', '%d/%b/%Y %H:%M:%S')]) def test_guess_datetime_format_with_locale_specific_formats( self, string, format): - # The month names will vary depending on the locale, in which - # case these wont be parsed properly (dateutil can't parse them) - tm._skip_if_has_locale() - result = parsing._guess_datetime_format(string) assert result == format + @td.skip_if_has_locale @is_dateutil_gt_261 @pytest.mark.parametrize( "string", @@ -143,10 +141,6 @@ def test_guess_datetime_format_with_locale_specific_formats( '30/Dec/2011 00:00:00']) def test_guess_datetime_format_with_locale_specific_formats_gt_261( self, string): - # The month names will vary depending on the locale, in which - # case these wont be parsed properly (dateutil can't parse them) - tm._skip_if_has_locale() - result = parsing._guess_datetime_format(string) assert result is None diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index b0d0e2a51b5f4..95410c6ea0105 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -8,6 +8,7 @@ import pandas as pd import pandas.util.testing as tm +import pandas.util._test_decorators as td from pandas._libs.tslib import iNaT from pandas.compat import lrange, StringIO, product from pandas.core.indexes.timedeltas import TimedeltaIndex @@ -17,7 +18,7 @@ Timestamp, to_datetime, offsets, timedelta_range) from pandas.util.testing import (assert_series_equal, assert_almost_equal, - assert_frame_equal, _skip_if_has_locale) + assert_frame_equal) from pandas.tests.series.common import TestData @@ -738,10 +739,9 @@ def test_between_time_types(self): pytest.raises(ValueError, series.between_time, datetime(2010, 1, 2, 1), datetime(2010, 1, 2, 5)) + @td.skip_if_has_locale def test_between_time_formats(self): # GH11818 - _skip_if_has_locale() - rng = date_range('1/1/2000', '1/5/2000', freq='5min') ts = DataFrame(np.random.randn(len(rng), 2), index=rng) diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index 6d15f360bcbe8..3fe4b8c3bb783 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -25,6 +25,7 @@ def test_foo(): """ import pytest +import locale from distutils.version import LooseVersion from pandas.compat import is_platform_windows, is_platform_32bit, PY3 @@ -81,6 +82,18 @@ def _skip_if_mpl_1_5(): mod.use("Agg", warn=False) +def _skip_if_has_locale(): + lang, _ = locale.getlocale() + if lang is not None: + return True + + +def _skip_if_not_us_locale(): + lang, _ = locale.getlocale() + if lang != 'en_US': + return True + + skip_if_no_mpl = pytest.mark.skipif(_skip_if_no_mpl(), reason="Missing matplotlib dependency") skip_if_mpl_1_5 = pytest.mark.skipif(_skip_if_mpl_1_5(), @@ -92,3 +105,10 @@ def _skip_if_mpl_1_5(): skip_if_windows_python_3 = pytest.mark.skipif(is_platform_windows() and PY3, reason=("not used on python3/" "win32")) +skip_if_has_locale = pytest.mark.skipif(_skip_if_has_locale(), + reason="Specific locale is set {lang}" + .format(lang=locale.getlocale()[0])) +skip_if_not_us_locale = pytest.mark.skipif(_skip_if_not_us_locale(), + reason="Specific locale is set " + "{lang}".format( + lang=locale.getlocale()[0])) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 81f84ea646c86..32f8c4884c99f 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -389,22 +389,6 @@ def skip_if_no_ne(engine='numexpr'): installed=_NUMEXPR_INSTALLED)) -def _skip_if_has_locale(): - import locale - lang, _ = locale.getlocale() - if lang is not None: - import pytest - pytest.skip("Specific locale is set {lang}".format(lang=lang)) - - -def _skip_if_not_us_locale(): - import locale - lang, _ = locale.getlocale() - if lang != 'en_US': - import pytest - pytest.skip("Specific locale is set {lang}".format(lang=lang)) - - def _skip_if_no_mock(): try: import mock # noqa