Skip to content

Commit c677ae4

Browse files
MarcoGorelliMarcoGorelli
authored andcommitted
REVERT caching in find_stack_level (pandas-dev#49053)
Revert "PERF cache find_stack_level (pandas-dev#48023)" This reverts commit 2f8d0a3. Co-authored-by: MarcoGorelli <> (cherry picked from commit 0106c26)
1 parent b8d2f46 commit c677ae4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+330
-478
lines changed

doc/source/development/contributing_codebase.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Otherwise, you need to do it manually:
134134
warnings.warn(
135135
'Use new_func instead.',
136136
FutureWarning,
137-
stacklevel=find_stack_level(inspect.currentframe()),
137+
stacklevel=find_stack_level(),
138138
)
139139
new_func()
140140

pandas/_config/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
ContextDecorator,
5555
contextmanager,
5656
)
57-
import inspect
5857
import re
5958
from typing import (
6059
Any,
@@ -662,7 +661,7 @@ def _warn_if_deprecated(key: str) -> bool:
662661
warnings.warn(
663662
d.msg,
664663
FutureWarning,
665-
stacklevel=find_stack_level(inspect.currentframe()),
664+
stacklevel=find_stack_level(),
666665
)
667666
else:
668667
msg = f"'{key}' is deprecated"
@@ -673,9 +672,7 @@ def _warn_if_deprecated(key: str) -> bool:
673672
else:
674673
msg += ", please refrain from using it."
675674

676-
warnings.warn(
677-
msg, FutureWarning, stacklevel=find_stack_level(inspect.currentframe())
678-
)
675+
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
679676
return True
680677
return False
681678

pandas/_libs/parsers.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ cdef class TextReader:
961961
"Defining usecols with out of bounds indices is deprecated "
962962
"and will raise a ParserError in a future version.",
963963
FutureWarning,
964-
stacklevel=find_stack_level(inspect.currentframe()),
964+
stacklevel=find_stack_level(),
965965
)
966966

967967
results = {}
@@ -1012,7 +1012,7 @@ cdef class TextReader:
10121012
warnings.warn((f"Both a converter and dtype were specified "
10131013
f"for column {name} - only the converter will "
10141014
f"be used."), ParserWarning,
1015-
stacklevel=find_stack_level(inspect.currentframe()))
1015+
stacklevel=find_stack_level())
10161016
results[i] = _apply_converter(conv, self.parser, i, start, end)
10171017
continue
10181018

pandas/_libs/tslib.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import warnings
32

43
cimport cython
@@ -848,7 +847,7 @@ cdef inline bint _parse_today_now(str val, int64_t* iresult, bint utc):
848847
"deprecated. In a future version, this will match Timestamp('now') "
849848
"and Timestamp.now()",
850849
FutureWarning,
851-
stacklevel=find_stack_level(inspect.currentframe()),
850+
stacklevel=find_stack_level(),
852851
)
853852

854853
return True

pandas/_libs/tslibs/conversion.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import inspect
2-
31
cimport cython
42

53
import warnings
@@ -291,7 +289,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
291289
"Conversion of non-round float with unit={unit} is ambiguous "
292290
"and will raise in a future version.",
293291
FutureWarning,
294-
stacklevel=find_stack_level(inspect.currentframe()),
292+
stacklevel=find_stack_level(),
295293
)
296294

297295
ts = cast_from_unit(ts, unit)

pandas/_libs/tslibs/nattype.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import warnings
32

43
from pandas.util._exceptions import find_stack_level
@@ -138,7 +137,7 @@ cdef class _NaT(datetime):
138137
"order to match the standard library behavior. "
139138
"In a future version these will be considered non-comparable.",
140139
FutureWarning,
141-
stacklevel=find_stack_level(inspect.currentframe()),
140+
stacklevel=find_stack_level(),
142141
)
143142
return False
144143

@@ -382,7 +381,7 @@ class NaTType(_NaT):
382381
warnings.warn(
383382
"NaT.freq is deprecated and will be removed in a future version.",
384383
FutureWarning,
385-
stacklevel=find_stack_level(inspect.currentframe()),
384+
stacklevel=find_stack_level(),
386385
)
387386
return None
388387

pandas/_libs/tslibs/offsets.pyx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import operator
32
import re
43
import time
@@ -502,7 +501,7 @@ cdef class BaseOffset:
502501
"DateOffset.__call__ is deprecated and will be removed in a future "
503502
"version. Use `offset + other` instead.",
504503
FutureWarning,
505-
stacklevel=find_stack_level(inspect.currentframe()),
504+
stacklevel=find_stack_level(),
506505
)
507506
return self._apply(other)
508507

@@ -512,7 +511,7 @@ cdef class BaseOffset:
512511
f"{type(self).__name__}.apply is deprecated and will be removed "
513512
"in a future version. Use `offset + other` instead",
514513
FutureWarning,
515-
stacklevel=find_stack_level(inspect.currentframe()),
514+
stacklevel=find_stack_level(),
516515
)
517516
return self._apply(other)
518517

@@ -823,15 +822,15 @@ cdef class BaseOffset:
823822
warnings.warn(
824823
"onOffset is a deprecated, use is_on_offset instead.",
825824
FutureWarning,
826-
stacklevel=find_stack_level(inspect.currentframe()),
825+
stacklevel=find_stack_level(),
827826
)
828827
return self.is_on_offset(dt)
829828

830829
def isAnchored(self) -> bool:
831830
warnings.warn(
832831
"isAnchored is a deprecated, use is_anchored instead.",
833832
FutureWarning,
834-
stacklevel=find_stack_level(inspect.currentframe()),
833+
stacklevel=find_stack_level(),
835834
)
836835
return self.is_anchored()
837836

pandas/_libs/tslibs/parsing.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Parsing functions for datetime and datetime-like strings.
33
"""
4-
import inspect
54
import re
65
import time
76
import warnings
@@ -217,15 +216,15 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
217216
format='MM/DD/YYYY',
218217
dayfirst='True',
219218
),
220-
stacklevel=find_stack_level(inspect.currentframe()),
219+
stacklevel=find_stack_level(),
221220
)
222221
elif not dayfirst and swapped_day_and_month:
223222
warnings.warn(
224223
PARSING_WARNING_MSG.format(
225224
format='DD/MM/YYYY',
226225
dayfirst='False (the default)',
227226
),
228-
stacklevel=find_stack_level(inspect.currentframe()),
227+
stacklevel=find_stack_level(),
229228
)
230229
# In Python <= 3.6.0 there is no range checking for invalid dates
231230
# in C api, thus we call faster C version for 3.6.1 or newer

pandas/_libs/tslibs/period.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import warnings
32

43
from pandas.util._exceptions import find_stack_level
@@ -1830,7 +1829,7 @@ cdef class _Period(PeriodMixin):
18301829
"be removed in a future version. Use "
18311830
"`per.to_timestamp(...).tz_localize(tz)` instead.",
18321831
FutureWarning,
1833-
stacklevel=find_stack_level(inspect.currentframe()),
1832+
stacklevel=find_stack_level(),
18341833
)
18351834

18361835
how = validate_end_alias(how)

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import collections
2-
import inspect
32
import warnings
43

54
from pandas.util._exceptions import find_stack_level
@@ -684,7 +683,7 @@ cdef inline timedelta_from_spec(object number, object frac, object unit):
684683
"Units 'M', 'Y' and 'y' do not represent unambiguous "
685684
"timedelta values and will be removed in a future version.",
686685
FutureWarning,
687-
stacklevel=find_stack_level(inspect.currentframe()),
686+
stacklevel=find_stack_level(),
688687
)
689688

690689
if unit == 'M':
@@ -1062,7 +1061,7 @@ cdef class _Timedelta(timedelta):
10621061
warnings.warn(
10631062
"Timedelta.freq is deprecated and will be removed in a future version",
10641063
FutureWarning,
1065-
stacklevel=find_stack_level(inspect.currentframe()),
1064+
stacklevel=find_stack_level(),
10661065
)
10671066
return None
10681067

@@ -1078,7 +1077,7 @@ cdef class _Timedelta(timedelta):
10781077
warnings.warn(
10791078
"Timedelta.is_populated is deprecated and will be removed in a future version",
10801079
FutureWarning,
1081-
stacklevel=find_stack_level(inspect.currentframe()),
1080+
stacklevel=find_stack_level(),
10821081
)
10831082
return self._is_populated
10841083

@@ -1285,7 +1284,7 @@ cdef class _Timedelta(timedelta):
12851284
warnings.warn(
12861285
"Timedelta.delta is deprecated and will be removed in a future version.",
12871286
FutureWarning,
1288-
stacklevel=find_stack_level(inspect.currentframe()),
1287+
stacklevel=find_stack_level(),
12891288
)
12901289
return self.value
12911290

0 commit comments

Comments
 (0)