Skip to content

Commit 8541084

Browse files
committed
revert some __init__ changes
1 parent 46f2aa2 commit 8541084

File tree

2 files changed

+103
-101
lines changed

2 files changed

+103
-101
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ repos:
146146
147147
# Check for deprecated messages without sphinx directive
148148
|(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)
149-
150-
# Check for e.g. ``stacklevel=5`` instead of
151-
# ``stacklevel=find_stack_level(inspect.currentframe())``
152-
|stacklevel=\d+
153149
types_or: [python, cython, rst]
150+
- id: stacklevel
151+
name: Use find_stack_level instead of setting stacklevel manually
152+
language: pygrep
153+
entry: 'stacklevel=\d+'
154+
types_or: [python, cython, rst]
155+
exclude: pandas/__init__\.py
154156
- id: cython-casting
155157
name: Check Cython casting is `<type>obj`, not `<type> obj`
156158
language: pygrep

pandas/__init__.py

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import inspect
4-
53
__docformat__ = "restructuredtext"
64

75
# Let users know if they're missing any of our hard dependencies
@@ -24,11 +22,7 @@
2422
from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401
2523

2624
try:
27-
from pandas._libs import (
28-
hashtable as _hashtable,
29-
lib as _lib,
30-
tslib as _tslib,
31-
)
25+
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
3226
except ImportError as _err: # pragma: no cover
3327
_module = _err.name
3428
raise ImportError(
@@ -40,137 +34,148 @@
4034
del _tslib, _lib, _hashtable
4135

4236
from pandas._config import (
43-
describe_option,
4437
get_option,
38+
set_option,
39+
reset_option,
40+
describe_option,
4541
option_context,
4642
options,
47-
reset_option,
48-
set_option,
4943
)
5044

51-
from pandas.util._print_versions import show_versions
52-
from pandas.util._tester import test
53-
54-
from pandas import (
55-
api,
56-
arrays,
57-
errors,
58-
io,
59-
plotting,
60-
tseries,
61-
)
62-
from pandas import testing # noqa:PDF015
45+
# let init-time option registration happen
46+
import pandas.core.config_init # pyright: ignore # noqa:F401
6347

64-
# use the closest tagged version if possible
65-
from pandas._version import get_versions
66-
from pandas.core.api import ( # dtype; missing; indexes; tseries; conversion; misc
67-
NA,
68-
BooleanDtype,
69-
Categorical,
70-
CategoricalDtype,
71-
CategoricalIndex,
72-
DataFrame,
73-
DateOffset,
74-
DatetimeIndex,
75-
DatetimeTZDtype,
76-
Flags,
77-
Float32Dtype,
78-
Float64Dtype,
79-
Grouper,
80-
Index,
81-
IndexSlice,
48+
from pandas.core.api import (
49+
# dtype
8250
Int8Dtype,
8351
Int16Dtype,
8452
Int32Dtype,
8553
Int64Dtype,
86-
Interval,
87-
IntervalDtype,
88-
IntervalIndex,
89-
MultiIndex,
90-
NamedAgg,
91-
NaT,
92-
Period,
93-
PeriodDtype,
94-
PeriodIndex,
95-
RangeIndex,
96-
Series,
97-
StringDtype,
98-
Timedelta,
99-
TimedeltaIndex,
100-
Timestamp,
10154
UInt8Dtype,
10255
UInt16Dtype,
10356
UInt32Dtype,
10457
UInt64Dtype,
105-
array,
106-
bdate_range,
107-
date_range,
108-
factorize,
109-
interval_range,
58+
Float32Dtype,
59+
Float64Dtype,
60+
CategoricalDtype,
61+
PeriodDtype,
62+
IntervalDtype,
63+
DatetimeTZDtype,
64+
StringDtype,
65+
BooleanDtype,
66+
# missing
67+
NA,
11068
isna,
11169
isnull,
11270
notna,
11371
notnull,
72+
# indexes
73+
Index,
74+
CategoricalIndex,
75+
RangeIndex,
76+
MultiIndex,
77+
IntervalIndex,
78+
TimedeltaIndex,
79+
DatetimeIndex,
80+
PeriodIndex,
81+
IndexSlice,
82+
# tseries
83+
NaT,
84+
Period,
11485
period_range,
115-
set_eng_float_format,
86+
Timedelta,
11687
timedelta_range,
117-
to_datetime,
88+
Timestamp,
89+
date_range,
90+
bdate_range,
91+
Interval,
92+
interval_range,
93+
DateOffset,
94+
# conversion
11895
to_numeric,
96+
to_datetime,
11997
to_timedelta,
98+
# misc
99+
Flags,
100+
Grouper,
101+
factorize,
120102
unique,
121103
value_counts,
104+
NamedAgg,
105+
array,
106+
Categorical,
107+
set_eng_float_format,
108+
Series,
109+
DataFrame,
122110
)
111+
123112
from pandas.core.arrays.sparse import SparseDtype
113+
114+
from pandas.tseries.api import infer_freq
115+
from pandas.tseries import offsets
116+
124117
from pandas.core.computation.api import eval
125118

126-
# let init-time option registration happen
127-
import pandas.core.config_init # pyright: ignore # noqa:F401
128119
from pandas.core.reshape.api import (
129120
concat,
130-
crosstab,
131-
cut,
132-
from_dummies,
133-
get_dummies,
134121
lreshape,
135122
melt,
123+
wide_to_long,
136124
merge,
137125
merge_asof,
138126
merge_ordered,
127+
crosstab,
139128
pivot,
140129
pivot_table,
130+
get_dummies,
131+
from_dummies,
132+
cut,
141133
qcut,
142-
wide_to_long,
143134
)
144135

145-
from pandas.io.api import ( # excel; parsers; pickle; pytables; sql; misc
136+
from pandas import api, arrays, errors, io, plotting, tseries
137+
from pandas import testing # noqa:PDF015
138+
from pandas.util._print_versions import show_versions
139+
140+
from pandas.io.api import (
141+
# excel
146142
ExcelFile,
147143
ExcelWriter,
144+
read_excel,
145+
# parsers
146+
read_csv,
147+
read_fwf,
148+
read_table,
149+
# pickle
150+
read_pickle,
151+
to_pickle,
152+
# pytables
148153
HDFStore,
154+
read_hdf,
155+
# sql
156+
read_sql,
157+
read_sql_query,
158+
read_sql_table,
159+
# misc
149160
read_clipboard,
150-
read_csv,
151-
read_excel,
161+
read_parquet,
162+
read_orc,
152163
read_feather,
153-
read_fwf,
154164
read_gbq,
155-
read_hdf,
156165
read_html,
166+
read_xml,
157167
read_json,
158-
read_orc,
159-
read_parquet,
160-
read_pickle,
168+
read_stata,
161169
read_sas,
162170
read_spss,
163-
read_sql,
164-
read_sql_query,
165-
read_sql_table,
166-
read_stata,
167-
read_table,
168-
read_xml,
169-
to_pickle,
170171
)
172+
171173
from pandas.io.json import _json_normalize as json_normalize
172-
from pandas.tseries import offsets
173-
from pandas.tseries.api import infer_freq
174+
175+
from pandas.util._tester import test
176+
177+
# use the closest tagged version if possible
178+
from pandas._version import get_versions
174179

175180
v = get_versions()
176181
__version__ = v.get("closest-tag", v["version"])
@@ -190,21 +195,16 @@ def __dir__() -> list[str]:
190195

191196
def __getattr__(name):
192197
import warnings
193-
from pandas.util._exceptions import find_stack_level
194198

195199
if name in __deprecated_num_index_names:
196200
warnings.warn(
197201
f"pandas.{name} is deprecated "
198202
"and will be removed from pandas in a future version. "
199203
"Use pandas.Index with the appropriate dtype instead.",
200204
FutureWarning,
201-
stacklevel=find_stack_level(inspect.currentframe()),
202-
)
203-
from pandas.core.api import (
204-
Float64Index,
205-
Int64Index,
206-
UInt64Index,
205+
stacklevel=2,
207206
)
207+
from pandas.core.api import Float64Index, Int64Index, UInt64Index
208208

209209
return {
210210
"Float64Index": Float64Index,
@@ -217,7 +217,7 @@ def __getattr__(name):
217217
"and will be removed from pandas in a future version. "
218218
"Import from datetime module instead.",
219219
FutureWarning,
220-
stacklevel=find_stack_level(inspect.currentframe()),
220+
stacklevel=2,
221221
)
222222

223223
from datetime import datetime as dt
@@ -231,7 +231,7 @@ def __getattr__(name):
231231
"and will be removed from pandas in a future version. "
232232
"Import numpy directly instead.",
233233
FutureWarning,
234-
stacklevel=find_stack_level(inspect.currentframe()),
234+
stacklevel=2,
235235
)
236236
import numpy as np
237237

@@ -242,7 +242,7 @@ def __getattr__(name):
242242
f"The {name} class is removed from pandas. Accessing it from "
243243
"the top-level namespace will also be removed in the next version.",
244244
FutureWarning,
245-
stacklevel=find_stack_level(inspect.currentframe()),
245+
stacklevel=2,
246246
)
247247

248248
return type(name, (), {})
@@ -254,7 +254,7 @@ def __getattr__(name):
254254
"and will be removed from pandas in a future version. "
255255
"Use pandas.arrays.SparseArray instead.",
256256
FutureWarning,
257-
stacklevel=find_stack_level(inspect.currentframe()),
257+
stacklevel=2,
258258
)
259259
from pandas.core.arrays.sparse import SparseArray as _SparseArray
260260

0 commit comments

Comments
 (0)