From 3439de400c67ac500761a6b8549ab84b9ec9cdd5 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 20 Nov 2017 11:40:47 -0800 Subject: [PATCH] Modify tests --- doc/source/whatsnew/v0.22.0.txt | 5 +++-- pandas/_libs/tslibs/fields.pyx | 4 ++-- pandas/tests/indexes/datetimes/test_misc.py | 22 +++++++++++++-------- pandas/tests/scalar/test_timestamp.py | 11 +++++++---- pandas/tests/series/test_datetime_values.py | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/source/whatsnew/v0.22.0.txt b/doc/source/whatsnew/v0.22.0.txt index 343b48c10c65e8..1839ae0cc45d81 100644 --- a/doc/source/whatsnew/v0.22.0.txt +++ b/doc/source/whatsnew/v0.22.0.txt @@ -28,7 +28,8 @@ Other Enhancements - :class:`pandas.io.formats.style.Styler` now has method ``hide_index()`` to determine whether the index will be rendered in ouptut (:issue:`14194`) - :class:`pandas.io.formats.style.Styler` now has method ``hide_columns()`` to determine whether columns will be hidden in output (:issue:`14194`) - Improved wording of ``ValueError`` raised in :func:`to_datetime` when ``unit=`` is passed with a non-convertible value (:issue:`14350`) -- :attr:`Timestamp.month_name`, :attr:`DatetimeIndex.month_name`, and :attr:`Series.dt.month_name` are now available (:issue:`12805`) +- :meth:`Timestamp.month_name`, :meth:`DatetimeIndex.month_name`, and :meth:`Series.dt.month_name` are now available (:issue:`12805`) +- :meth:`Timestamp.day_name` and :meth:`DatetimeIndex.day_name` are now available to return day names with a specified locale (:issue:`12806`) - .. _whatsnew_0220.api_breaking: @@ -101,7 +102,7 @@ Bug Fixes Conversion ^^^^^^^^^^ -- Bug in :attr:`Timestamp.weekday_name` and :attr:`DatetimeIndex.weekday_name` not returning locale aware values (:issue:`12806`) +- - - diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index c3600579bc8eab..6b908a31d978ad 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -88,8 +88,8 @@ def get_date_name_field(ndarray[int64_t] dtindex, object field, out = np.empty(count, dtype=object) if field == 'weekday_name': - _dayname = np.array(['monday', 'tuesday', 'wednesday', 'thursday', - 'friday', 'saturday', 'sunday'], + _dayname = np.array(['Monday', 'Tuesday', 'Wednesday', 'Thursday', + 'Friday', 'Saturday', 'Sunday'], dtype=np.object_) for i in range(count): if dtindex[i] == NPY_NAT: diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index 5a27df962cbb49..15b2b6ddd80f58 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -328,19 +328,24 @@ def test_datetimeindex_accessors(self): assert [d.weekofyear for d in dates] == expected # GH 12806 - @pytest.mark.skipif(tm.get_locales() is None or len(tm.get_locales()) == 0, - reason='No available locales') + @pytest.mark.skipif(not tm.get_locales(), reason='No available locales') @pytest.mark.parametrize('time_locale', tm.get_locales()) def test_datetime_name_accessors(self, time_locale): with tm.set_locale(time_locale, locale.LC_TIME): # GH 11128 dti = DatetimeIndex(freq='D', start=datetime(1998, 1, 1), periods=365) - for day, name in zip(range(4, 11), calendar.day_name): + english_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', + 'Friday', 'Saturday', 'Sunday'] + for day, name, eng_name in zip(range(4, 11), + calendar.day_name, + english_days): # Test Monday -> Sunday - assert dti.weekday_name[day] == name.capitalize() - date = datetime(2016, 4, day) - assert Timestamp(date).weekday_name == name.capitalize() + assert dti.weekday_name[day] == eng_name + assert dti.day_name(time_locale=time_locale) == name + ts = Timestamp(datetime(2016, 4, day)) + assert ts.weekday_name == eng_name + assert ts.day_name(time_locale=time_locale) == name # GH 12805 dti = DatetimeIndex(freq='M', start='2012', end='2013') @@ -349,8 +354,9 @@ def test_datetime_name_accessors(self, time_locale): expected = Index([month.capitalize() for month in calendar.month_name[1:]]) tm.assert_index_equal(result, expected) - for date, result in zip(dti, calendar.month_name[1:]): - assert date.month_name == result.capitalize() + for date, expected in zip(dti, calendar.month_name[1:]): + result = date.month_name(time_locale=time_locale) + assert result == expected.capitalize() def test_nanosecond_field(self): dti = DatetimeIndex(np.arange(10)) diff --git a/pandas/tests/scalar/test_timestamp.py b/pandas/tests/scalar/test_timestamp.py index b162158d3b1572..9722dcbf4c036d 100644 --- a/pandas/tests/scalar/test_timestamp.py +++ b/pandas/tests/scalar/test_timestamp.py @@ -600,16 +600,19 @@ def check(value, equal): assert getattr(ts, end) # GH 12806 - @pytest.mark.skipif(tm.get_locales() is None or len(tm.get_locales()) == 0, - reason='No available locales') + @pytest.mark.skipif(not tm.get_locales(), reason='No available locales') @pytest.mark.parametrize('data', [Timestamp('2017-08-28 23:00:00'), Timestamp('2017-08-28 23:00:00', tz='EST')]) @pytest.mark.parametrize('time_locale', tm.get_locales()) - def test_weekday_name(self, data, time_locale): + def test_day_name(self, data, time_locale): # GH 17354 + # Test .weekday_name and .day_name() + assert data.weekday_name == 'Monday' with tm.set_locale(time_locale, locale.LC_TIME): - assert data.weekday_name == calendar.day_name[0].capitalize() + expected = calendar.day_name[0].capitalize() + result = data.day_name(time_locale) + assert result == expected def test_pprint(self): # GH12622 diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index 6a7e74dfe18895..e810eadd2dee97 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -32,7 +32,7 @@ def test_dt_namespace_accessor(self): ok_for_dt = DatetimeIndex._datetimelike_ops ok_for_dt_methods = ['to_period', 'to_pydatetime', 'tz_localize', 'tz_convert', 'normalize', 'strftime', 'round', - 'floor', 'ceil', 'weekday_name', 'month_name'] + 'floor', 'ceil', 'weekday_name'] ok_for_td = TimedeltaIndex._datetimelike_ops ok_for_td_methods = ['components', 'to_pytimedelta', 'total_seconds', 'round', 'floor', 'ceil']