Skip to content

Commit 746db2a

Browse files
author
MarcoGorelli
committed
rewrite find_stack_level calls
1 parent c671f6c commit 746db2a

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

+331
-447
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

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
@@ -847,7 +846,7 @@ cdef inline bint _parse_today_now(str val, int64_t* iresult, bint utc):
847846
"deprecated. In a future version, this will match Timestamp('now') "
848847
"and Timestamp.now()",
849848
FutureWarning,
850-
stacklevel=find_stack_level(inspect.currentframe()),
849+
stacklevel=find_stack_level(),
851850
)
852851

853852
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
@@ -286,7 +285,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
286285
"Conversion of non-round float with unit={unit} is ambiguous "
287286
"and will raise in a future version.",
288287
FutureWarning,
289-
stacklevel=find_stack_level(inspect.currentframe()),
288+
stacklevel=find_stack_level(),
290289
)
291290

292291
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)

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
@@ -687,7 +686,7 @@ cdef inline timedelta_from_spec(object number, object frac, object unit):
687686
"Units 'M', 'Y' and 'y' do not represent unambiguous "
688687
"timedelta values and will be removed in a future version.",
689688
FutureWarning,
690-
stacklevel=find_stack_level(inspect.currentframe()),
689+
stacklevel=find_stack_level(),
691690
)
692691

693692
if unit == 'M':
@@ -1066,7 +1065,7 @@ cdef class _Timedelta(timedelta):
10661065
warnings.warn(
10671066
"Timedelta.freq is deprecated and will be removed in a future version",
10681067
FutureWarning,
1069-
stacklevel=find_stack_level(inspect.currentframe()),
1068+
stacklevel=find_stack_level(),
10701069
)
10711070
return None
10721071

@@ -1082,7 +1081,7 @@ cdef class _Timedelta(timedelta):
10821081
warnings.warn(
10831082
"Timedelta.is_populated is deprecated and will be removed in a future version",
10841083
FutureWarning,
1085-
stacklevel=find_stack_level(inspect.currentframe()),
1084+
stacklevel=find_stack_level(),
10861085
)
10871086
return self._is_populated
10881087

@@ -1289,7 +1288,7 @@ cdef class _Timedelta(timedelta):
12891288
warnings.warn(
12901289
"Timedelta.delta is deprecated and will be removed in a future version.",
12911290
FutureWarning,
1292-
stacklevel=find_stack_level(inspect.currentframe()),
1291+
stacklevel=find_stack_level(),
12931292
)
12941293
return self.value
12951294

0 commit comments

Comments
 (0)