Skip to content

Commit

Permalink
REF: make ccalendar self-contained (#35119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Jul 7, 2020
1 parent a207fb1 commit c2dfde4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
23 changes: 0 additions & 23 deletions pandas/_libs/tslibs/ccalendar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import cython

from numpy cimport int64_t, int32_t

from locale import LC_TIME

from pandas._config.localization import set_locale
from pandas._libs.tslibs.strptime import LocaleTime

# ----------------------------------------------------------------------
# Constants

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

day_of_year = mo_off + day
return day_of_year


def get_locale_names(name_type: str, locale: object = None):
"""
Returns an array of localized day or month names.
Parameters
----------
name_type : string, attribute of LocaleTime() in which to return localized
names
locale : string
Returns
-------
list of locale names
"""
with set_locale(locale, LC_TIME):
return getattr(LocaleTime(), name_type)
26 changes: 23 additions & 3 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Functions for accessing attributes of Timestamp/datetime64/datetime-like
objects and arrays
"""
from locale import LC_TIME

import cython
from cython import Py_ssize_t
Expand All @@ -11,9 +12,9 @@ cimport numpy as cnp
from numpy cimport ndarray, int64_t, int32_t, int8_t, uint32_t
cnp.import_array()

from pandas._libs.tslibs.ccalendar import (
get_locale_names, MONTHS_FULL, DAYS_FULL,
)
from pandas._config.localization import set_locale

from pandas._libs.tslibs.ccalendar import MONTHS_FULL, DAYS_FULL
from pandas._libs.tslibs.ccalendar cimport (
DAY_NANOS,
get_days_in_month, is_leapyear, dayofweek, get_week_of_year,
Expand All @@ -24,6 +25,7 @@ from pandas._libs.tslibs.np_datetime cimport (
npy_datetimestruct, pandas_timedeltastruct, dt64_to_dtstruct,
td64_to_tdstruct)
from pandas._libs.tslibs.nattype cimport NPY_NAT
from pandas._libs.tslibs.strptime import LocaleTime


def get_time_micros(const int64_t[:] dtindex):
Expand Down Expand Up @@ -704,3 +706,21 @@ def build_isocalendar_sarray(const int64_t[:] dtindex):
iso_weeks[i] = ret_val[1]
days[i] = ret_val[2]
return out


def get_locale_names(name_type: str, locale: object = None):
"""
Returns an array of localized day or month names.
Parameters
----------
name_type : string, attribute of LocaleTime() in which to return localized
names
locale : string
Returns
-------
list of locale names
"""
with set_locale(locale, LC_TIME):
return getattr(LocaleTime(), name_type)

0 comments on commit c2dfde4

Please sign in to comment.