Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REVERT caching in find_stack_level #49053

Merged
merged 1 commit into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/development/contributing_codebase.rst
Expand Up @@ -139,7 +139,7 @@ Otherwise, you need to do it manually:
warnings.warn(
'Use new_func instead.',
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
new_func()

Expand Down
7 changes: 2 additions & 5 deletions pandas/_config/config.py
Expand Up @@ -54,7 +54,6 @@
ContextDecorator,
contextmanager,
)
import inspect
import re
from typing import (
Any,
Expand Down Expand Up @@ -662,7 +661,7 @@ def _warn_if_deprecated(key: str) -> bool:
warnings.warn(
d.msg,
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
else:
msg = f"'{key}' is deprecated"
Expand All @@ -673,9 +672,7 @@ def _warn_if_deprecated(key: str) -> bool:
else:
msg += ", please refrain from using it."

warnings.warn(
msg, FutureWarning, stacklevel=find_stack_level(inspect.currentframe())
)
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
return True
return False

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/parsers.pyx
Expand Up @@ -972,7 +972,7 @@ cdef class TextReader:
"Defining usecols with out of bounds indices is deprecated "
"and will raise a ParserError in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

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

Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslib.pyx
@@ -1,4 +1,3 @@
import inspect
import warnings

cimport cython
Expand Down Expand Up @@ -847,7 +846,7 @@ cdef inline bint _parse_today_now(str val, int64_t* iresult, bint utc):
"deprecated. In a future version, this will match Timestamp('now') "
"and Timestamp.now()",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

return True
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/conversion.pyx
@@ -1,4 +1,3 @@
import inspect
import warnings

import numpy as np
Expand Down Expand Up @@ -286,7 +285,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
"Conversion of non-round float with unit={unit} is ambiguous "
"and will raise in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

ts = cast_from_unit(ts, unit)
Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/tslibs/nattype.pyx
@@ -1,4 +1,3 @@
import inspect
import warnings

from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -134,7 +133,7 @@ cdef class _NaT(datetime):
"order to match the standard library behavior. "
"In a future version these will be considered non-comparable.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return False

Expand Down Expand Up @@ -378,7 +377,7 @@ class NaTType(_NaT):
warnings.warn(
"NaT.freq is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return None

Expand Down
9 changes: 4 additions & 5 deletions pandas/_libs/tslibs/offsets.pyx
@@ -1,4 +1,3 @@
import inspect
import re
import time
import warnings
Expand Down Expand Up @@ -501,7 +500,7 @@ cdef class BaseOffset:
"DateOffset.__call__ is deprecated and will be removed in a future "
"version. Use `offset + other` instead.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self._apply(other)

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

Expand Down Expand Up @@ -825,15 +824,15 @@ cdef class BaseOffset:
warnings.warn(
"onOffset is a deprecated, use is_on_offset instead.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self.is_on_offset(dt)

def isAnchored(self) -> bool:
warnings.warn(
"isAnchored is a deprecated, use is_anchored instead.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self.is_anchored()

Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/tslibs/parsing.pyx
@@ -1,7 +1,6 @@
"""
Parsing functions for datetime and datetime-like strings.
"""
import inspect
import re
import time
import warnings
Expand Down Expand Up @@ -218,15 +217,15 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
format='MM/DD/YYYY',
dayfirst='True',
),
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
elif not dayfirst and swapped_day_and_month:
warnings.warn(
PARSING_WARNING_MSG.format(
format='DD/MM/YYYY',
dayfirst='False (the default)',
),
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
# In Python <= 3.6.0 there is no range checking for invalid dates
# in C api, thus we call faster C version for 3.6.1 or newer
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/period.pyx
@@ -1,4 +1,3 @@
import inspect
import warnings

from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -1830,7 +1829,7 @@ cdef class _Period(PeriodMixin):
"be removed in a future version. Use "
"`per.to_timestamp(...).tz_localize(tz)` instead.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

how = validate_end_alias(how)
Expand Down
9 changes: 4 additions & 5 deletions pandas/_libs/tslibs/timedeltas.pyx
@@ -1,5 +1,4 @@
import collections
import inspect
import warnings

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

if unit == 'M':
Expand Down Expand Up @@ -1066,7 +1065,7 @@ cdef class _Timedelta(timedelta):
warnings.warn(
"Timedelta.freq is deprecated and will be removed in a future version",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return None

Expand All @@ -1082,7 +1081,7 @@ cdef class _Timedelta(timedelta):
warnings.warn(
"Timedelta.is_populated is deprecated and will be removed in a future version",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self._is_populated

Expand Down Expand Up @@ -1289,7 +1288,7 @@ cdef class _Timedelta(timedelta):
warnings.warn(
"Timedelta.delta is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self.value

Expand Down
21 changes: 10 additions & 11 deletions pandas/_libs/tslibs/timestamps.pyx
Expand Up @@ -6,7 +6,6 @@ construction requirements, we need to do object instantiation in python
(see Timestamp class below). This will serve as a C extension type that
shadows the python class, where we do any heavy lifting.
"""
import inspect
import warnings

cimport cython
Expand Down Expand Up @@ -251,7 +250,7 @@ cdef class _Timestamp(ABCTimestamp):
warnings.warn(
"Timestamp.freq is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self._freq

Expand Down Expand Up @@ -371,7 +370,7 @@ cdef class _Timestamp(ABCTimestamp):
"In a future version these will be considered non-comparable. "
"Use 'ts == pd.Timestamp(date)' or 'ts.date() == date' instead.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return NotImplemented
else:
Expand Down Expand Up @@ -626,7 +625,7 @@ cdef class _Timestamp(ABCTimestamp):
"version. When you have a freq, use "
f"freq.{field}(timestamp) instead.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

@property
Expand Down Expand Up @@ -1132,7 +1131,7 @@ cdef class _Timestamp(ABCTimestamp):
"""
if self.nanosecond != 0 and warn:
warnings.warn("Discarding nonzero nanoseconds in conversion.",
UserWarning, stacklevel=find_stack_level(inspect.currentframe()))
UserWarning, stacklevel=find_stack_level())

return datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second,
Expand Down Expand Up @@ -1211,7 +1210,7 @@ cdef class _Timestamp(ABCTimestamp):
warnings.warn(
"Converting to Period representation will drop timezone information.",
UserWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

if freq is None:
Expand All @@ -1220,7 +1219,7 @@ cdef class _Timestamp(ABCTimestamp):
"In a future version, calling 'Timestamp.to_period()' without "
"passing a 'freq' will raise an exception.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)

return Period(self, freq=freq)
Expand Down Expand Up @@ -1412,7 +1411,7 @@ class Timestamp(_Timestamp):
"Timestamp.utcfromtimestamp(ts).tz_localize(None). "
"To get the future behavior, use Timestamp.fromtimestamp(ts, 'UTC')",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return cls(datetime.utcfromtimestamp(ts))

Expand Down Expand Up @@ -1648,7 +1647,7 @@ class Timestamp(_Timestamp):
"as a wall time, not a UTC time. To interpret as a UTC time, "
"use `Timestamp(dt64).tz_localize('UTC').tz_convert(tz)`",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
# Once this deprecation is enforced, we can do
# return Timestamp(ts_input).tz_localize(tzobj)
Expand All @@ -1671,7 +1670,7 @@ class Timestamp(_Timestamp):
"The 'freq' argument in Timestamp is deprecated and will be "
"removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
if not is_offset_object(freq):
freq = to_offset(freq)
Expand Down Expand Up @@ -2007,7 +2006,7 @@ timedelta}, default 'raise'
warnings.warn(
"Timestamp.freqstr is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return self._freqstr

Expand Down
11 changes: 5 additions & 6 deletions pandas/_testing/asserters.py
@@ -1,6 +1,5 @@
from __future__ import annotations

import inspect
from typing import (
Literal,
cast,
Expand Down Expand Up @@ -113,7 +112,7 @@ def assert_almost_equal(
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

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

Expand Down Expand Up @@ -830,7 +829,7 @@ def assert_extension_array_equal(
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

Expand Down Expand Up @@ -985,7 +984,7 @@ def assert_series_equal(
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

Expand Down Expand Up @@ -1278,7 +1277,7 @@ def assert_frame_equal(
"is deprecated and will be removed in a future version. "
"You can stop passing 'check_less_precise' to silence this warning.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
rtol = atol = _get_tol_from_less_precise(check_less_precise)

Expand Down
3 changes: 1 addition & 2 deletions pandas/compat/_optional.py
@@ -1,7 +1,6 @@
from __future__ import annotations

import importlib
import inspect
import sys
import types
import warnings
Expand Down Expand Up @@ -165,7 +164,7 @@ def import_optional_dependency(
warnings.warn(
msg,
UserWarning,
stacklevel=find_stack_level(inspect.currentframe()),
stacklevel=find_stack_level(),
)
return None
elif errors == "raise":
Expand Down