Skip to content

Commit c2dfde4

Browse files
authored
REF: make ccalendar self-contained (#35119)
1 parent a207fb1 commit c2dfde4

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

pandas/_libs/tslibs/ccalendar.pyx

-23
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import cython
77

88
from numpy cimport int64_t, int32_t
99

10-
from locale import LC_TIME
11-
12-
from pandas._config.localization import set_locale
13-
from pandas._libs.tslibs.strptime import LocaleTime
14-
1510
# ----------------------------------------------------------------------
1611
# Constants
1712

@@ -246,21 +241,3 @@ cpdef int32_t get_day_of_year(int year, int month, int day) nogil:
246241

247242
day_of_year = mo_off + day
248243
return day_of_year
249-
250-
251-
def get_locale_names(name_type: str, locale: object = None):
252-
"""
253-
Returns an array of localized day or month names.
254-
255-
Parameters
256-
----------
257-
name_type : string, attribute of LocaleTime() in which to return localized
258-
names
259-
locale : string
260-
261-
Returns
262-
-------
263-
list of locale names
264-
"""
265-
with set_locale(locale, LC_TIME):
266-
return getattr(LocaleTime(), name_type)

pandas/_libs/tslibs/fields.pyx

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Functions for accessing attributes of Timestamp/datetime64/datetime-like
33
objects and arrays
44
"""
5+
from locale import LC_TIME
56

67
import cython
78
from cython import Py_ssize_t
@@ -11,9 +12,9 @@ cimport numpy as cnp
1112
from numpy cimport ndarray, int64_t, int32_t, int8_t, uint32_t
1213
cnp.import_array()
1314

14-
from pandas._libs.tslibs.ccalendar import (
15-
get_locale_names, MONTHS_FULL, DAYS_FULL,
16-
)
15+
from pandas._config.localization import set_locale
16+
17+
from pandas._libs.tslibs.ccalendar import MONTHS_FULL, DAYS_FULL
1718
from pandas._libs.tslibs.ccalendar cimport (
1819
DAY_NANOS,
1920
get_days_in_month, is_leapyear, dayofweek, get_week_of_year,
@@ -24,6 +25,7 @@ from pandas._libs.tslibs.np_datetime cimport (
2425
npy_datetimestruct, pandas_timedeltastruct, dt64_to_dtstruct,
2526
td64_to_tdstruct)
2627
from pandas._libs.tslibs.nattype cimport NPY_NAT
28+
from pandas._libs.tslibs.strptime import LocaleTime
2729

2830

2931
def get_time_micros(const int64_t[:] dtindex):
@@ -704,3 +706,21 @@ def build_isocalendar_sarray(const int64_t[:] dtindex):
704706
iso_weeks[i] = ret_val[1]
705707
days[i] = ret_val[2]
706708
return out
709+
710+
711+
def get_locale_names(name_type: str, locale: object = None):
712+
"""
713+
Returns an array of localized day or month names.
714+
715+
Parameters
716+
----------
717+
name_type : string, attribute of LocaleTime() in which to return localized
718+
names
719+
locale : string
720+
721+
Returns
722+
-------
723+
list of locale names
724+
"""
725+
with set_locale(locale, LC_TIME):
726+
return getattr(LocaleTime(), name_type)

0 commit comments

Comments
 (0)