Skip to content

Commit ab6384e

Browse files
committed
move find_stack_level to _libs
1 parent 6e1a040 commit ab6384e

Some content is hidden

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

76 files changed

+104
-99
lines changed

pandas/_libs/exceptions.pyx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import inspect
2+
import os
3+
4+
5+
cpdef int find_stack_level():
6+
"""
7+
Find the first place in the stack that is not inside pandas
8+
(tests notwithstanding).
9+
"""
10+
cdef:
11+
int n
12+
str pkg_dir, test_dir, fname
13+
14+
import pandas as pd
15+
16+
17+
pkg_dir = os.path.dirname(pd.__file__)
18+
test_dir = os.path.join(pkg_dir, "tests")
19+
20+
# https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slow
21+
frame = inspect.currentframe()
22+
n = 1
23+
while frame:
24+
fname = inspect.getfile(frame)
25+
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
26+
frame = frame.f_back
27+
n += 1
28+
else:
29+
break
30+
return n

pandas/_libs/interval.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from cpython.datetime cimport (
99
import_datetime,
1010
)
1111

12-
from pandas.util._exceptions import find_stack_level
12+
from pandas._libs.exceptions import find_stack_level
1313

1414
import_datetime()
1515

pandas/_testing/asserters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import numpy as np
1010

11+
from pandas._libs.exceptions import find_stack_level
1112
from pandas._libs.lib import (
1213
NoDefault,
1314
no_default,
1415
)
1516
from pandas._libs.missing import is_matching_na
1617
from pandas._libs.sparse import SparseIndex
1718
import pandas._libs.testing as _testing
18-
from pandas.util._exceptions import find_stack_level
1919

2020
from pandas.core.dtypes.common import (
2121
is_bool,

pandas/core/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import warnings
1010

11+
from pandas._libs.exceptions import find_stack_level
1112
from pandas.util._decorators import doc
12-
from pandas.util._exceptions import find_stack_level
1313

1414

1515
class DirNamesMixin:

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
iNaT,
2626
lib,
2727
)
28+
from pandas._libs.exceptions import find_stack_level
2829
from pandas._typing import (
2930
AnyArrayLike,
3031
ArrayLike,
@@ -34,7 +35,6 @@
3435
npt,
3536
)
3637
from pandas.util._decorators import doc
37-
from pandas.util._exceptions import find_stack_level
3838

3939
from pandas.core.dtypes.cast import (
4040
construct_1d_object_array_from_listlike,

pandas/core/apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pandas._config import option_context
2626

2727
from pandas._libs import lib
28+
from pandas._libs.exceptions import find_stack_level
2829
from pandas._typing import (
2930
AggFuncType,
3031
AggFuncTypeBase,
@@ -39,7 +40,6 @@
3940
SpecificationError,
4041
)
4142
from pandas.util._decorators import cache_readonly
42-
from pandas.util._exceptions import find_stack_level
4343

4444
from pandas.core.dtypes.cast import is_nested_object
4545
from pandas.core.dtypes.common import (

pandas/core/arraylike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import numpy as np
1414

1515
from pandas._libs import lib
16+
from pandas._libs.exceptions import find_stack_level
1617
from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
17-
from pandas.util._exceptions import find_stack_level
1818

1919
from pandas.core.dtypes.generic import ABCNDFrame
2020

pandas/core/arrays/arrow/_arrow_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import numpy as np
77
import pyarrow
88

9+
from pandas._libs.exceptions import find_stack_level
910
from pandas._typing import IntervalInclusiveType
1011
from pandas.errors import PerformanceWarning
1112
from pandas.util._decorators import deprecate_kwarg
12-
from pandas.util._exceptions import find_stack_level
1313

1414
from pandas.core.arrays.interval import VALID_INCLUSIVE
1515

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import numpy as np
2828

2929
from pandas._libs import lib
30+
from pandas._libs.exceptions import find_stack_level
3031
from pandas._typing import (
3132
ArrayLike,
3233
AstypeArg,
@@ -48,7 +49,6 @@
4849
cache_readonly,
4950
deprecate_nonkeyword_arguments,
5051
)
51-
from pandas.util._exceptions import find_stack_level
5252
from pandas.util._validators import (
5353
validate_bool_kwarg,
5454
validate_fillna_kwargs,

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
lib,
3131
)
3232
from pandas._libs.arrays import NDArrayBacked
33+
from pandas._libs.exceptions import find_stack_level
3334
from pandas._libs.lib import (
3435
NoDefault,
3536
no_default,
@@ -49,7 +50,6 @@
4950
deprecate_kwarg,
5051
deprecate_nonkeyword_arguments,
5152
)
52-
from pandas.util._exceptions import find_stack_level
5353
from pandas.util._validators import validate_bool_kwarg
5454

5555
from pandas.core.dtypes.cast import coerce_indexer_dtype

0 commit comments

Comments
 (0)