Skip to content

Commit c677ae4

Browse files
MarcoGorelliMarcoGorelli
authored and
MarcoGorelli
committed
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

+1-1
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

+2-5
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

+2-2
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

+1-2
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

+1-3
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

+2-3
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

+4-5
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

+2-3
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

+1-2
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

+4-5
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

pandas/_libs/tslibs/timestamps.pyx

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ construction requirements, we need to do object instantiation in python
66
(see Timestamp class below). This will serve as a C extension type that
77
shadows the python class, where we do any heavy lifting.
88
"""
9-
import inspect
109
import warnings
1110

1211
cimport cython
@@ -257,7 +256,7 @@ cdef class _Timestamp(ABCTimestamp):
257256
warnings.warn(
258257
"Timestamp.freq is deprecated and will be removed in a future version.",
259258
FutureWarning,
260-
stacklevel=find_stack_level(inspect.currentframe()),
259+
stacklevel=find_stack_level(),
261260
)
262261
return self._freq
263262

@@ -369,7 +368,7 @@ cdef class _Timestamp(ABCTimestamp):
369368
"In a future version these will be considered non-comparable. "
370369
"Use 'ts == pd.Timestamp(date)' or 'ts.date() == date' instead.",
371370
FutureWarning,
372-
stacklevel=find_stack_level(inspect.currentframe()),
371+
stacklevel=find_stack_level(),
373372
)
374373
return NotImplemented
375374
else:
@@ -670,7 +669,7 @@ cdef class _Timestamp(ABCTimestamp):
670669
"version. When you have a freq, use "
671670
f"freq.{field}(timestamp) instead.",
672671
FutureWarning,
673-
stacklevel=find_stack_level(inspect.currentframe()),
672+
stacklevel=find_stack_level(),
674673
)
675674

676675
@property
@@ -1176,7 +1175,7 @@ cdef class _Timestamp(ABCTimestamp):
11761175
"""
11771176
if self.nanosecond != 0 and warn:
11781177
warnings.warn("Discarding nonzero nanoseconds in conversion.",
1179-
UserWarning, stacklevel=find_stack_level(inspect.currentframe()))
1178+
UserWarning, stacklevel=find_stack_level())
11801179

11811180
return datetime(self.year, self.month, self.day,
11821181
self.hour, self.minute, self.second,
@@ -1255,7 +1254,7 @@ cdef class _Timestamp(ABCTimestamp):
12551254
warnings.warn(
12561255
"Converting to Period representation will drop timezone information.",
12571256
UserWarning,
1258-
stacklevel=find_stack_level(inspect.currentframe()),
1257+
stacklevel=find_stack_level(),
12591258
)
12601259

12611260
if freq is None:
@@ -1264,7 +1263,7 @@ cdef class _Timestamp(ABCTimestamp):
12641263
"In a future version, calling 'Timestamp.to_period()' without "
12651264
"passing a 'freq' will raise an exception.",
12661265
FutureWarning,
1267-
stacklevel=find_stack_level(inspect.currentframe()),
1266+
stacklevel=find_stack_level(),
12681267
)
12691268

12701269
return Period(self, freq=freq)
@@ -1456,7 +1455,7 @@ class Timestamp(_Timestamp):
14561455
"Timestamp.utcfromtimestamp(ts).tz_localize(None). "
14571456
"To get the future behavior, use Timestamp.fromtimestamp(ts, 'UTC')",
14581457
FutureWarning,
1459-
stacklevel=find_stack_level(inspect.currentframe()),
1458+
stacklevel=find_stack_level(),
14601459
)
14611460
return cls(datetime.utcfromtimestamp(ts))
14621461

@@ -1692,7 +1691,7 @@ class Timestamp(_Timestamp):
16921691
"as a wall time, not a UTC time. To interpret as a UTC time, "
16931692
"use `Timestamp(dt64).tz_localize('UTC').tz_convert(tz)`",
16941693
FutureWarning,
1695-
stacklevel=find_stack_level(inspect.currentframe()),
1694+
stacklevel=find_stack_level(),
16961695
)
16971696
# Once this deprecation is enforced, we can do
16981697
# return Timestamp(ts_input).tz_localize(tzobj)
@@ -1709,7 +1708,7 @@ class Timestamp(_Timestamp):
17091708
"The 'freq' argument in Timestamp is deprecated and will be "
17101709
"removed in a future version.",
17111710
FutureWarning,
1712-
stacklevel=find_stack_level(inspect.currentframe()),
1711+
stacklevel=find_stack_level(),
17131712
)
17141713
if not is_offset_object(freq):
17151714
freq = to_offset(freq)
@@ -2045,7 +2044,7 @@ timedelta}, default 'raise'
20452044
warnings.warn(
20462045
"Timestamp.freqstr is deprecated and will be removed in a future version.",
20472046
FutureWarning,
2048-
stacklevel=find_stack_level(inspect.currentframe()),
2047+
stacklevel=find_stack_level(),
20492048
)
20502049
return self._freqstr
20512050

pandas/_testing/asserters.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import inspect
43
from typing import (
54
Literal,
65
cast,
@@ -113,7 +112,7 @@ def assert_almost_equal(
113112
"is deprecated and will be removed in a future version. "
114113
"You can stop passing 'check_less_precise' to silence this warning.",
115114
FutureWarning,
116-
stacklevel=find_stack_level(inspect.currentframe()),
115+
stacklevel=find_stack_level(),
117116
)
118117
rtol = atol = _get_tol_from_less_precise(check_less_precise)
119118

@@ -340,7 +339,7 @@ def _get_ilevel_values(index, level):
340339
"is deprecated and will be removed in a future version. "
341340
"You can stop passing 'check_less_precise' to silence this warning.",
342341
FutureWarning,
343-
stacklevel=find_stack_level(inspect.currentframe()),
342+
stacklevel=find_stack_level(),
344343
)
345344
rtol = atol = _get_tol_from_less_precise(check_less_precise)
346345

@@ -819,7 +818,7 @@ def assert_extension_array_equal(
819818
"is deprecated and will be removed in a future version. "
820819
"You can stop passing 'check_less_precise' to silence this warning.",
821820
FutureWarning,
822-
stacklevel=find_stack_level(inspect.currentframe()),
821+
stacklevel=find_stack_level(),
823822
)
824823
rtol = atol = _get_tol_from_less_precise(check_less_precise)
825824

@@ -974,7 +973,7 @@ def assert_series_equal(
974973
"is deprecated and will be removed in a future version. "
975974
"You can stop passing 'check_less_precise' to silence this warning.",
976975
FutureWarning,
977-
stacklevel=find_stack_level(inspect.currentframe()),
976+
stacklevel=find_stack_level(),
978977
)
979978
rtol = atol = _get_tol_from_less_precise(check_less_precise)
980979

@@ -1267,7 +1266,7 @@ def assert_frame_equal(
12671266
"is deprecated and will be removed in a future version. "
12681267
"You can stop passing 'check_less_precise' to silence this warning.",
12691268
FutureWarning,
1270-
stacklevel=find_stack_level(inspect.currentframe()),
1269+
stacklevel=find_stack_level(),
12711270
)
12721271
rtol = atol = _get_tol_from_less_precise(check_less_precise)
12731272

pandas/compat/_optional.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import importlib
4-
import inspect
54
import sys
65
import types
76
import warnings
@@ -165,7 +164,7 @@ def import_optional_dependency(
165164
warnings.warn(
166165
msg,
167166
UserWarning,
168-
stacklevel=find_stack_level(inspect.currentframe()),
167+
stacklevel=find_stack_level(),
169168
)
170169
return None
171170
elif errors == "raise":

0 commit comments

Comments
 (0)