MCPcopy
hub / github.com/pandas-dev/pandas / find_stack_level

Function find_stack_level

pandas/util/_exceptions.py:37–63  ·  view source on GitHub ↗

Find the first place in the stack that is not inside pandas (tests notwithstanding).

()

Source from the content-addressed store, hash-verified

35
36
37def find_stack_level() -> int:
38 """
39 Find the first place in the stack that is not inside pandas
40 (tests notwithstanding).
41 """
42
43 import pandas as pd
44
45 pkg_dir = os.path.dirname(pd.__file__)
46 test_dir = os.path.join(pkg_dir, "tests")
47
48 # https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow
49 frame: FrameType | None = inspect.currentframe()
50 try:
51 n = 0
52 while frame:
53 filename = inspect.getfile(frame)
54 if filename.startswith(pkg_dir) and not filename.startswith(test_dir):
55 frame = frame.f_back
56 n += 1
57 else:
58 break
59 finally:
60 # See note in
61 # https://docs.python.org/3/library/inspect.html#inspect.Traceback
62 del frame
63 return n
64
65
66@contextlib.contextmanager

Callers 15

_derive_colorsFunction · 0.90
_validate_color_argsMethod · 0.90
_validate_log_kwdMethod · 0.90
create_subplotsFunction · 0.90
_validate_color_argsMethod · 0.90
combine_firstMethod · 0.90
mapMethod · 0.90
interpolateMethod · 0.90
__init__Method · 0.90
modeFunction · 0.90
decoratorFunction · 0.90

Calls 2

startswithMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected