Skip to content

Commit 942a3b9

Browse files
author
MarcoGorelli
committed
revert caching stacklevel
1 parent f2a91a0 commit 942a3b9

Some content is hidden

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

99 files changed

+336
-470
lines changed

doc/source/development/contributing_codebase.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Otherwise, you need to do it manually:
139139
warnings.warn(
140140
'Use new_func instead.',
141141
FutureWarning,
142-
stacklevel=find_stack_level(inspect.currentframe()),
142+
stacklevel=find_stack_level(),
143143
)
144144
new_func()
145145

doc/source/whatsnew/v1.5.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Fixed regressions
8686
- Fixed regression in :meth:`DataFrame.apply` when passing non-zero ``axis`` via keyword argument (:issue:`48656`)
8787
- Fixed regression in :meth:`Series.groupby` and :meth:`DataFrame.groupby` when the grouper is a nullable data type (e.g. :class:`Int64`) or a PyArrow-backed string array, contains null values, and ``dropna=False`` (:issue:`48794`)
8888
- Fixed regression in :class:`ExcelWriter` where the ``book`` attribute could no longer be set; however setting this attribute is now deprecated and this ability will be removed in a future version of pandas (:issue:`48780`)
89+
- Fixed regression causing memory leak when finding stacklevel when emitting warnings (:issue:`49052`)
8990

9091
.. ---------------------------------------------------------------------------
9192

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
@@ -972,7 +972,7 @@ cdef class TextReader:
972972
"Defining usecols with out of bounds indices is deprecated "
973973
"and will raise a ParserError in a future version.",
974974
FutureWarning,
975-
stacklevel=find_stack_level(inspect.currentframe()),
975+
stacklevel=find_stack_level(),
976976
)
977977

978978
results = {}
@@ -1023,7 +1023,7 @@ cdef class TextReader:
10231023
warnings.warn((f"Both a converter and dtype were specified "
10241024
f"for column {name} - only the converter will "
10251025
f"be used."), ParserWarning,
1026-
stacklevel=find_stack_level(inspect.currentframe()))
1026+
stacklevel=find_stack_level())
10271027
results[i] = _apply_converter(conv, self.parser, i, start, end)
10281028
continue
10291029

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
@@ -845,7 +844,7 @@ cdef inline bint _parse_today_now(str val, int64_t* iresult, bint utc):
845844
"deprecated. In a future version, this will match Timestamp('now') "
846845
"and Timestamp.now()",
847846
FutureWarning,
848-
stacklevel=find_stack_level(inspect.currentframe()),
847+
stacklevel=find_stack_level(),
849848
)
850849

851850
return True

pandas/_libs/tslibs/conversion.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
import numpy as np
@@ -275,7 +274,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
275274
"Conversion of non-round float with unit={unit} is ambiguous "
276275
"and will raise in a future version.",
277276
FutureWarning,
278-
stacklevel=find_stack_level(inspect.currentframe()),
277+
stacklevel=find_stack_level(),
279278
)
280279

281280
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
@@ -134,7 +133,7 @@ cdef class _NaT(datetime):
134133
"order to match the standard library behavior. "
135134
"In a future version these will be considered non-comparable.",
136135
FutureWarning,
137-
stacklevel=find_stack_level(inspect.currentframe()),
136+
stacklevel=find_stack_level(),
138137
)
139138
return False
140139

@@ -378,7 +377,7 @@ class NaTType(_NaT):
378377
warnings.warn(
379378
"NaT.freq is deprecated and will be removed in a future version.",
380379
FutureWarning,
381-
stacklevel=find_stack_level(inspect.currentframe()),
380+
stacklevel=find_stack_level(),
382381
)
383382
return None
384383

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 re
32
import time
43
import warnings
@@ -501,7 +500,7 @@ cdef class BaseOffset:
501500
"DateOffset.__call__ is deprecated and will be removed in a future "
502501
"version. Use `offset + other` instead.",
503502
FutureWarning,
504-
stacklevel=find_stack_level(inspect.currentframe()),
503+
stacklevel=find_stack_level(),
505504
)
506505
return self._apply(other)
507506

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

@@ -825,15 +824,15 @@ cdef class BaseOffset:
825824
warnings.warn(
826825
"onOffset is a deprecated, use is_on_offset instead.",
827826
FutureWarning,
828-
stacklevel=find_stack_level(inspect.currentframe()),
827+
stacklevel=find_stack_level(),
829828
)
830829
return self.is_on_offset(dt)
831830

832831
def isAnchored(self) -> bool:
833832
warnings.warn(
834833
"isAnchored is a deprecated, use is_anchored instead.",
835834
FutureWarning,
836-
stacklevel=find_stack_level(inspect.currentframe()),
835+
stacklevel=find_stack_level(),
837836
)
838837
return self.is_anchored()
839838

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
@@ -218,15 +217,15 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
218217
format='MM/DD/YYYY',
219218
dayfirst='True',
220219
),
221-
stacklevel=find_stack_level(inspect.currentframe()),
220+
stacklevel=find_stack_level(),
222221
)
223222
elif not dayfirst and swapped_day_and_month:
224223
warnings.warn(
225224
PARSING_WARNING_MSG.format(
226225
format='DD/MM/YYYY',
227226
dayfirst='False (the default)',
228227
),
229-
stacklevel=find_stack_level(inspect.currentframe()),
228+
stacklevel=find_stack_level(),
230229
)
231230
# In Python <= 3.6.0 there is no range checking for invalid dates
232231
# 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)

0 commit comments

Comments
 (0)