We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f7f67ad commit 22e384dCopy full SHA for 22e384d
pandas/util/_exceptions.py
@@ -29,17 +29,20 @@ def find_stack_level() -> int:
29
Find the first place in the stack that is not inside pandas
30
(tests notwithstanding).
31
"""
32
- stack = inspect.stack()
33
34
import pandas as pd
35
36
pkg_dir = os.path.dirname(pd.__file__)
37
test_dir = os.path.join(pkg_dir, "tests")
38
39
- for n in range(len(stack)):
40
- fname = stack[n].filename
+ # https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow
+ frame = inspect.currentframe()
+ n = 0
41
+ while frame:
42
+ fname = inspect.getfile(frame)
43
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
- continue
44
+ frame = frame.f_back
45
+ n += 1
46
else:
47
break
48
return n
0 commit comments