Skip to content

Commit

Permalink
Modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Nov 20, 2017
1 parent 76c2f37 commit 3439de4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
5 changes: 3 additions & 2 deletions doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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`)
-
-
-

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 14 additions & 8 deletions pandas/tests/indexes/datetimes/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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))
Expand Down
11 changes: 7 additions & 4 deletions pandas/tests/scalar/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_datetime_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 3439de4

Please sign in to comment.