Skip to content

Commit 2a49371

Browse files
committed
PERF: eliminate repeated get_option imports in period.pyx
1 parent ecadba7 commit 2a49371

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ Performance Improvements
12541254
- Improved performance of :meth:`~DataFrame.where` for Categorical data (:issue:`24077`)
12551255
- Improved performance of iterating over a :class:`Series`. Using :meth:`DataFrame.itertuples` now creates iterators
12561256
without internally allocating lists of all elements (:issue:`20783`)
1257+
- Improved performance of :class:`Period` constructor, additionally benefitting ``PeriodArray`` and ``PeriodIndex`` creation (:issue:`24084` and :issue:`24118`)
12571258

12581259
.. _whatsnew_0240.docs:
12591260

pandas/_libs/tslibs/parsing.pyx

+14-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ cdef set _not_datelike_strings = {'a', 'A', 'm', 'M', 'p', 'P', 't', 'T'}
4747

4848
# ----------------------------------------------------------------------
4949

50+
_get_option = None
51+
52+
53+
def get_option(param):
54+
""" Defer import of get_option to break an import cycle that caused
55+
significant performance degradation in Period construction. See
56+
GH#24118 for details
57+
"""
58+
global _get_option
59+
if _get_option is None:
60+
from pandas.core.config import get_option
61+
_get_option = get_option
62+
return _get_option(param)
63+
5064

5165
def parse_datetime_string(date_string, freq=None, dayfirst=False,
5266
yearfirst=False, **kwargs):
@@ -117,7 +131,6 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None):
117131
freq = freq.rule_code
118132

119133
if dayfirst is None or yearfirst is None:
120-
from pandas.core.config import get_option
121134
if dayfirst is None:
122135
dayfirst = get_option("display.date_dayfirst")
123136
if yearfirst is None:

0 commit comments

Comments
 (0)