From 830602add9120af33edba2184df4ada21fb01a6e Mon Sep 17 00:00:00 2001 From: Eduardo Chaves Date: Fri, 3 Feb 2023 20:05:08 -0300 Subject: [PATCH 1/4] DOC: Additions to month_name & day_name --- pandas/core/arrays/datetimes.py | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 0766b1c6a5262..6ec6ff7e836d5 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1202,7 +1202,8 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: ---------- locale : str, optional Locale determining the language in which to return the month name. - Default is English locale. + Default is English locale (``'en_US.utf8'``). Use the command + ``locale -a`` on your terminal to look for your locale language code. Returns ------- @@ -1229,6 +1230,20 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: dtype='datetime64[ns]', freq='M') >>> idx.month_name() Index(['January', 'February', 'March'], dtype='object') + + Using the ``locale`` parameter you can set a different locale language, + for example: ``idx.month_name(locale='pt_BR.utf8')`` will return month + names in Brazilian Portuguese language. + + To know your locale code you can just use ``locale -a`` in your terminal + to look for your specific language code. + + >>> idx = pd.date_range(start='2018-01', freq='M', periods=3) + >>> idx + DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], + dtype='datetime64[ns]', freq='M') + >>> idx.month_name(locale='pt_BR.utf8') + Index(['Janeiro', 'Fevereiro', 'Março'], dtype='object') """ values = self._local_timestamps() @@ -1246,7 +1261,8 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: ---------- locale : str, optional Locale determining the language in which to return the day name. - Default is English locale. + Default is English locale (``'en_US.utf8'``). Use the command + ``locale -a`` on your terminal to look for your locale language code. Returns ------- @@ -1273,6 +1289,20 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: dtype='datetime64[ns]', freq='D') >>> idx.day_name() Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object') + + Using the ``locale`` parameter you can set a different locale language, + for example: ``idx.day_name(locale='pt_BR.utf8')`` will return day + names in Brazilian Portuguese language. + + To know your locale code you can just use ``locale -a`` in your terminal + to look for your specific language code. + + >>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3) + >>> idx + DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], + dtype='datetime64[ns]', freq='D') + >>> idx.day_name(locale='pt_BR.utf8') + Index(['Segunda', 'Terça', 'Quarta'], dtype='object') """ values = self._local_timestamps() From 93c737fb0cab3f837746ed7b65c234d94e978736 Mon Sep 17 00:00:00 2001 From: Eduardo Chaves Date: Fri, 3 Feb 2023 22:08:08 -0300 Subject: [PATCH 2/4] FIX: Removing whitespaces --- pandas/core/arrays/datetimes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 6ec6ff7e836d5..f0e03246d6c9b 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1232,10 +1232,10 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: Index(['January', 'February', 'March'], dtype='object') Using the ``locale`` parameter you can set a different locale language, - for example: ``idx.month_name(locale='pt_BR.utf8')`` will return month + for example: ``idx.month_name(locale='pt_BR.utf8')`` will return month names in Brazilian Portuguese language. - To know your locale code you can just use ``locale -a`` in your terminal + To know your locale code you can just use ``locale -a`` in your terminal to look for your specific language code. >>> idx = pd.date_range(start='2018-01', freq='M', periods=3) @@ -1291,10 +1291,10 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object') Using the ``locale`` parameter you can set a different locale language, - for example: ``idx.day_name(locale='pt_BR.utf8')`` will return day + for example: ``idx.day_name(locale='pt_BR.utf8')`` will return day names in Brazilian Portuguese language. - To know your locale code you can just use ``locale -a`` in your terminal + To know your locale code you can just use ``locale -a`` in your terminal to look for your specific language code. >>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3) From fad385f47ee7d08ef85229bea6ca1fc8f7cbc00e Mon Sep 17 00:00:00 2001 From: Eduardo Chaves Date: Mon, 6 Feb 2023 23:17:40 -0300 Subject: [PATCH 3/4] doctest +SKIP: because of unavailable locale --- pandas/core/arrays/datetimes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index f0e03246d6c9b..93eb9ad68f6a5 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1242,7 +1242,7 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: >>> idx DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], dtype='datetime64[ns]', freq='M') - >>> idx.month_name(locale='pt_BR.utf8') + >>> idx.month_name(locale='pt_BR.utf8') # doctest: +SKIP Index(['Janeiro', 'Fevereiro', 'Março'], dtype='object') """ values = self._local_timestamps() @@ -1301,7 +1301,7 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: >>> idx DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') - >>> idx.day_name(locale='pt_BR.utf8') + >>> idx.day_name(locale='pt_BR.utf8') # doctest: +SKIP Index(['Segunda', 'Terça', 'Quarta'], dtype='object') """ values = self._local_timestamps() From 476df204e7b80e3af9fb0ebe54859199f09b4ab4 Mon Sep 17 00:00:00 2001 From: Eduardo Chaves Date: Tue, 7 Feb 2023 15:57:53 -0300 Subject: [PATCH 4/4] specifying the OS in which the command locale -a works --- pandas/core/arrays/datetimes.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 93eb9ad68f6a5..659a5d1a7181e 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1203,7 +1203,8 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: locale : str, optional Locale determining the language in which to return the month name. Default is English locale (``'en_US.utf8'``). Use the command - ``locale -a`` on your terminal to look for your locale language code. + ``locale -a`` on your terminal on Unix systems to find your locale + language code. Returns ------- @@ -1235,9 +1236,6 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: for example: ``idx.month_name(locale='pt_BR.utf8')`` will return month names in Brazilian Portuguese language. - To know your locale code you can just use ``locale -a`` in your terminal - to look for your specific language code. - >>> idx = pd.date_range(start='2018-01', freq='M', periods=3) >>> idx DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], @@ -1262,7 +1260,8 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: locale : str, optional Locale determining the language in which to return the day name. Default is English locale (``'en_US.utf8'``). Use the command - ``locale -a`` on your terminal to look for your locale language code. + ``locale -a`` on your terminal on Unix systems to find your locale + language code. Returns ------- @@ -1294,9 +1293,6 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: for example: ``idx.day_name(locale='pt_BR.utf8')`` will return day names in Brazilian Portuguese language. - To know your locale code you can just use ``locale -a`` in your terminal - to look for your specific language code. - >>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3) >>> idx DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'],