Skip to content

Commit 3439de4

Browse files
committed
Modify tests
1 parent 76c2f37 commit 3439de4

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

doc/source/whatsnew/v0.22.0.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Other Enhancements
2828
- :class:`pandas.io.formats.style.Styler` now has method ``hide_index()`` to determine whether the index will be rendered in ouptut (:issue:`14194`)
2929
- :class:`pandas.io.formats.style.Styler` now has method ``hide_columns()`` to determine whether columns will be hidden in output (:issue:`14194`)
3030
- Improved wording of ``ValueError`` raised in :func:`to_datetime` when ``unit=`` is passed with a non-convertible value (:issue:`14350`)
31-
- :attr:`Timestamp.month_name`, :attr:`DatetimeIndex.month_name`, and :attr:`Series.dt.month_name` are now available (:issue:`12805`)
31+
- :meth:`Timestamp.month_name`, :meth:`DatetimeIndex.month_name`, and :meth:`Series.dt.month_name` are now available (:issue:`12805`)
32+
- :meth:`Timestamp.day_name` and :meth:`DatetimeIndex.day_name` are now available to return day names with a specified locale (:issue:`12806`)
3233
-
3334

3435
.. _whatsnew_0220.api_breaking:
@@ -101,7 +102,7 @@ Bug Fixes
101102
Conversion
102103
^^^^^^^^^^
103104

104-
- Bug in :attr:`Timestamp.weekday_name` and :attr:`DatetimeIndex.weekday_name` not returning locale aware values (:issue:`12806`)
105+
-
105106
-
106107
-
107108

pandas/_libs/tslibs/fields.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def get_date_name_field(ndarray[int64_t] dtindex, object field,
8888
out = np.empty(count, dtype=object)
8989

9090
if field == 'weekday_name':
91-
_dayname = np.array(['monday', 'tuesday', 'wednesday', 'thursday',
92-
'friday', 'saturday', 'sunday'],
91+
_dayname = np.array(['Monday', 'Tuesday', 'Wednesday', 'Thursday',
92+
'Friday', 'Saturday', 'Sunday'],
9393
dtype=np.object_)
9494
for i in range(count):
9595
if dtindex[i] == NPY_NAT:

pandas/tests/indexes/datetimes/test_misc.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,24 @@ def test_datetimeindex_accessors(self):
328328
assert [d.weekofyear for d in dates] == expected
329329

330330
# GH 12806
331-
@pytest.mark.skipif(tm.get_locales() is None or len(tm.get_locales()) == 0,
332-
reason='No available locales')
331+
@pytest.mark.skipif(not tm.get_locales(), reason='No available locales')
333332
@pytest.mark.parametrize('time_locale', tm.get_locales())
334333
def test_datetime_name_accessors(self, time_locale):
335334
with tm.set_locale(time_locale, locale.LC_TIME):
336335
# GH 11128
337336
dti = DatetimeIndex(freq='D', start=datetime(1998, 1, 1),
338337
periods=365)
339-
for day, name in zip(range(4, 11), calendar.day_name):
338+
english_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
339+
'Friday', 'Saturday', 'Sunday']
340+
for day, name, eng_name in zip(range(4, 11),
341+
calendar.day_name,
342+
english_days):
340343
# Test Monday -> Sunday
341-
assert dti.weekday_name[day] == name.capitalize()
342-
date = datetime(2016, 4, day)
343-
assert Timestamp(date).weekday_name == name.capitalize()
344+
assert dti.weekday_name[day] == eng_name
345+
assert dti.day_name(time_locale=time_locale) == name
346+
ts = Timestamp(datetime(2016, 4, day))
347+
assert ts.weekday_name == eng_name
348+
assert ts.day_name(time_locale=time_locale) == name
344349

345350
# GH 12805
346351
dti = DatetimeIndex(freq='M', start='2012', end='2013')
@@ -349,8 +354,9 @@ def test_datetime_name_accessors(self, time_locale):
349354
expected = Index([month.capitalize()
350355
for month in calendar.month_name[1:]])
351356
tm.assert_index_equal(result, expected)
352-
for date, result in zip(dti, calendar.month_name[1:]):
353-
assert date.month_name == result.capitalize()
357+
for date, expected in zip(dti, calendar.month_name[1:]):
358+
result = date.month_name(time_locale=time_locale)
359+
assert result == expected.capitalize()
354360

355361
def test_nanosecond_field(self):
356362
dti = DatetimeIndex(np.arange(10))

pandas/tests/scalar/test_timestamp.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,19 @@ def check(value, equal):
600600
assert getattr(ts, end)
601601

602602
# GH 12806
603-
@pytest.mark.skipif(tm.get_locales() is None or len(tm.get_locales()) == 0,
604-
reason='No available locales')
603+
@pytest.mark.skipif(not tm.get_locales(), reason='No available locales')
605604
@pytest.mark.parametrize('data',
606605
[Timestamp('2017-08-28 23:00:00'),
607606
Timestamp('2017-08-28 23:00:00', tz='EST')])
608607
@pytest.mark.parametrize('time_locale', tm.get_locales())
609-
def test_weekday_name(self, data, time_locale):
608+
def test_day_name(self, data, time_locale):
610609
# GH 17354
610+
# Test .weekday_name and .day_name()
611+
assert data.weekday_name == 'Monday'
611612
with tm.set_locale(time_locale, locale.LC_TIME):
612-
assert data.weekday_name == calendar.day_name[0].capitalize()
613+
expected = calendar.day_name[0].capitalize()
614+
result = data.day_name(time_locale)
615+
assert result == expected
613616

614617
def test_pprint(self):
615618
# GH12622

pandas/tests/series/test_datetime_values.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_dt_namespace_accessor(self):
3232
ok_for_dt = DatetimeIndex._datetimelike_ops
3333
ok_for_dt_methods = ['to_period', 'to_pydatetime', 'tz_localize',
3434
'tz_convert', 'normalize', 'strftime', 'round',
35-
'floor', 'ceil', 'weekday_name', 'month_name']
35+
'floor', 'ceil', 'weekday_name']
3636
ok_for_td = TimedeltaIndex._datetimelike_ops
3737
ok_for_td_methods = ['components', 'to_pytimedelta', 'total_seconds',
3838
'round', 'floor', 'ceil']

0 commit comments

Comments
 (0)