Skip to content

Commit 040682b

Browse files
topper-123Terji Petersen
authored and
MarcoGorelli
committed
DEPR: remove Int64Index, UInt64Index, Float64Index from public namespace (pandas-dev#49670)
* DEPR: remove Int64Index, UInt64Index, Float64Index * fix isort * fix stuff * fix pyright & mypy * fix isort * fix mypy Co-authored-by: Terji Petersen <[email protected]>
1 parent afb2caa commit 040682b

File tree

14 files changed

+44
-81
lines changed

14 files changed

+44
-81
lines changed

asv_bench/benchmarks/hash_functions.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ def time_unique(self, exponent):
5757
class NumericSeriesIndexing:
5858

5959
params = [
60-
(pd.Int64Index, pd.UInt64Index, pd.Float64Index),
60+
(np.int64, np.uint64, np.float64),
6161
(10**4, 10**5, 5 * 10**5, 10**6, 5 * 10**6),
6262
]
63-
param_names = ["index_dtype", "N"]
63+
param_names = ["dtype", "N"]
6464

65-
def setup(self, index, N):
66-
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)))
67-
indices = index(vals)
65+
def setup(self, dtype, N):
66+
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)), dtype=dtype)
67+
indices = pd.Index(vals)
6868
self.data = pd.Series(np.arange(N), index=indices)
6969

7070
def time_loc_slice(self, index, N):
@@ -75,15 +75,15 @@ def time_loc_slice(self, index, N):
7575
class NumericSeriesIndexingShuffled:
7676

7777
params = [
78-
(pd.Int64Index, pd.UInt64Index, pd.Float64Index),
78+
(np.int64, np.uint64, np.float64),
7979
(10**4, 10**5, 5 * 10**5, 10**6, 5 * 10**6),
8080
]
81-
param_names = ["index_dtype", "N"]
81+
param_names = ["dtype", "N"]
8282

83-
def setup(self, index, N):
84-
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)))
83+
def setup(self, dtype, N):
84+
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)), dtype=dtype)
8585
np.random.shuffle(vals)
86-
indices = index(vals)
86+
indices = pd.Index(vals)
8787
self.data = pd.Series(np.arange(N), index=indices)
8888

8989
def time_loc_slice(self, index, N):

asv_bench/benchmarks/index_cached_properties.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setup(self, index_type):
3030
elif index_type == "DatetimeIndex":
3131
self.idx = pd.date_range("1/1/2000", freq="T", periods=N)
3232
elif index_type == "Int64Index":
33-
self.idx = pd.Index(range(N))
33+
self.idx = pd.Index(range(N), dtype="int64")
3434
elif index_type == "PeriodIndex":
3535
self.idx = pd.period_range("1/1/2000", freq="T", periods=N)
3636
elif index_type == "RangeIndex":
@@ -40,9 +40,9 @@ def setup(self, index_type):
4040
elif index_type == "TimedeltaIndex":
4141
self.idx = pd.TimedeltaIndex(range(N))
4242
elif index_type == "Float64Index":
43-
self.idx = pd.Float64Index(range(N))
43+
self.idx = pd.Index(range(N), dtype="float64")
4444
elif index_type == "UInt64Index":
45-
self.idx = pd.UInt64Index(range(N))
45+
self.idx = pd.Index(range(N), dtype="uint64")
4646
elif index_type == "CategoricalIndex":
4747
self.idx = pd.CategoricalIndex(range(N), range(N))
4848
else:

asv_bench/benchmarks/index_object.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from pandas import (
66
DatetimeIndex,
7-
Float64Index,
87
Index,
98
IntervalIndex,
109
MultiIndex,
@@ -202,8 +201,8 @@ class Float64IndexMethod:
202201
# GH 13166
203202
def setup(self):
204203
N = 100_000
205-
a = np.arange(N)
206-
self.ind = Float64Index(a * 4.8000000418824129e-08)
204+
a = np.arange(N, dtype=np.float64)
205+
self.ind = Index(a * 4.8000000418824129e-08)
207206

208207
def time_get_loc(self):
209208
self.ind.get_loc(0)

asv_bench/benchmarks/indexing.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
from pandas import (
1313
CategoricalIndex,
1414
DataFrame,
15-
Float64Index,
16-
Int64Index,
15+
Index,
1716
IntervalIndex,
1817
MultiIndex,
1918
Series,
20-
UInt64Index,
2119
concat,
2220
date_range,
2321
option_context,
@@ -30,17 +28,17 @@
3028
class NumericSeriesIndexing:
3129

3230
params = [
33-
(Int64Index, UInt64Index, Float64Index),
31+
(np.int64, np.uint64, np.float64),
3432
("unique_monotonic_inc", "nonunique_monotonic_inc"),
3533
]
36-
param_names = ["index_dtype", "index_structure"]
34+
param_names = ["dtype", "index_structure"]
3735

38-
def setup(self, index, index_structure):
36+
def setup(self, dtype, index_structure):
3937
N = 10**6
4038
indices = {
41-
"unique_monotonic_inc": index(range(N)),
42-
"nonunique_monotonic_inc": index(
43-
list(range(55)) + [54] + list(range(55, N - 1))
39+
"unique_monotonic_inc": Index(range(N), dtype=dtype),
40+
"nonunique_monotonic_inc": Index(
41+
list(range(55)) + [54] + list(range(55, N - 1)), dtype=dtype
4442
),
4543
}
4644
self.data = Series(np.random.rand(N), index=indices[index_structure])
@@ -159,17 +157,17 @@ def time_boolean_rows_boolean(self):
159157
class DataFrameNumericIndexing:
160158

161159
params = [
162-
(Int64Index, UInt64Index, Float64Index),
160+
(np.int64, np.uint64, np.float64),
163161
("unique_monotonic_inc", "nonunique_monotonic_inc"),
164162
]
165-
param_names = ["index_dtype", "index_structure"]
163+
param_names = ["dtype", "index_structure"]
166164

167-
def setup(self, index, index_structure):
165+
def setup(self, dtype, index_structure):
168166
N = 10**5
169167
indices = {
170-
"unique_monotonic_inc": index(range(N)),
171-
"nonunique_monotonic_inc": index(
172-
list(range(55)) + [54] + list(range(55, N - 1))
168+
"unique_monotonic_inc": Index(range(N), dtype=dtype),
169+
"nonunique_monotonic_inc": Index(
170+
list(range(55)) + [54] + list(range(55, N - 1)), dtype=dtype
173171
),
174172
}
175173
self.idx_dupe = np.array(range(30)) * 99
@@ -201,7 +199,7 @@ class Take:
201199
def setup(self, index):
202200
N = 100000
203201
indexes = {
204-
"int": Int64Index(np.arange(N)),
202+
"int": Index(np.arange(N), dtype=np.int64),
205203
"datetime": date_range("2011-01-01", freq="S", periods=N),
206204
}
207205
index = indexes[index]

doc/source/reference/indexing.rst

-3
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ Numeric Index
166166
:template: autosummary/class_without_autosummary.rst
167167

168168
RangeIndex
169-
Int64Index
170-
UInt64Index
171-
Float64Index
172169

173170
.. We need this autosummary so that the methods are generated.
174171
.. Separate block, since they aren't classes.

pandas/__init__.py

-32
Original file line numberDiff line numberDiff line change
@@ -183,38 +183,6 @@
183183
__git_version__ = v.get("full-revisionid")
184184
del get_versions, v
185185

186-
# GH 27101
187-
__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"]
188-
189-
190-
def __dir__() -> list[str]:
191-
# GH43028
192-
# Int64Index etc. are deprecated, but we still want them to be available in the dir.
193-
# Remove in Pandas 2.0, when we remove Int64Index etc. from the code base.
194-
return list(globals().keys()) + __deprecated_num_index_names
195-
196-
197-
def __getattr__(name):
198-
import warnings
199-
200-
if name in __deprecated_num_index_names:
201-
warnings.warn(
202-
f"pandas.{name} is deprecated "
203-
"and will be removed from pandas in a future version. "
204-
"Use pandas.Index with the appropriate dtype instead.",
205-
FutureWarning,
206-
stacklevel=2,
207-
)
208-
from pandas.core.api import Float64Index, Int64Index, UInt64Index
209-
210-
return {
211-
"Float64Index": Float64Index,
212-
"Int64Index": Int64Index,
213-
"UInt64Index": UInt64Index,
214-
}[name]
215-
216-
raise AttributeError(f"module 'pandas' has no attribute '{name}'")
217-
218186

219187
# module level doc-string
220188
__doc__ = """

pandas/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
Series,
6363
Timedelta,
6464
Timestamp,
65+
compat,
6566
)
6667
import pandas._testing as tm
6768
from pandas.core import ops
@@ -79,7 +80,7 @@
7980
has_pyarrow = True
8081

8182
zoneinfo = None
82-
if pd.compat.PY39:
83+
if compat.PY39:
8384
# Import "zoneinfo" could not be resolved (reportMissingImports)
8485
import zoneinfo # type: ignore[no-redef]
8586

pandas/core/arrays/datetimelike.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,9 @@ def _addsub_object_array(self, other: np.ndarray, op):
13541354

13551355
res_values = op(self.astype("O"), np.asarray(other))
13561356

1357-
result = pd_array(res_values.ravel())
1358-
result = extract_array(result, extract_numpy=True).reshape(self.shape)
1357+
ext_arr = pd_array(res_values.ravel())
1358+
result = cast(np.ndarray, extract_array(ext_arr, extract_numpy=True))
1359+
result = result.reshape(self.shape)
13591360
return result
13601361

13611362
def _time_shift(

pandas/core/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666

6767
if TYPE_CHECKING:
6868
from pandas import (
69-
ExtensionArray,
7069
Index,
7170
Series,
7271
)
72+
from pandas.core.arrays.base import ExtensionArray
7373

7474

7575
def array(

pandas/core/dtypes/generic.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
CategoricalIndex,
1414
DataFrame,
1515
DatetimeIndex,
16-
Float64Index,
1716
Index,
18-
Int64Index,
1917
IntervalIndex,
2018
MultiIndex,
2119
PeriodIndex,
2220
RangeIndex,
2321
Series,
2422
TimedeltaIndex,
25-
UInt64Index,
2623
)
2724
from pandas.core.arrays import (
2825
DatetimeArray,
@@ -32,6 +29,11 @@
3229
TimedeltaArray,
3330
)
3431
from pandas.core.generic import NDFrame
32+
from pandas.core.indexes.api import (
33+
Float64Index,
34+
Int64Index,
35+
UInt64Index,
36+
)
3537

3638

3739
# define abstract base classes to enable isinstance type checking on our

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
from pandas.core.tools.times import to_time
6262

6363
if TYPE_CHECKING:
64-
from pandas import (
64+
from pandas.core.api import (
6565
DataFrame,
6666
Float64Index,
6767
PeriodIndex,

pandas/core/internals/array_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
)
9797

9898
if TYPE_CHECKING:
99-
from pandas import Float64Index
99+
from pandas.core.api import Float64Index
100100

101101

102102
T = TypeVar("T", bound="BaseArrayManager")

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
from pandas.core.indexers import check_setitem_lengths
110110

111111
if TYPE_CHECKING:
112-
from pandas import (
112+
from pandas.core.api import (
113113
Float64Index,
114114
Index,
115115
)

pandas/tests/api/test_api.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,14 @@ class TestPDApi(Base):
5555
"DatetimeIndex",
5656
"ExcelFile",
5757
"ExcelWriter",
58-
"Float64Index",
5958
"Flags",
6059
"Grouper",
6160
"HDFStore",
6261
"Index",
63-
"Int64Index",
6462
"MultiIndex",
6563
"Period",
6664
"PeriodIndex",
6765
"RangeIndex",
68-
"UInt64Index",
6966
"Series",
7067
"SparseDtype",
7168
"StringDtype",
@@ -93,7 +90,7 @@ class TestPDApi(Base):
9390
]
9491

9592
# these are already deprecated; awaiting removal
96-
deprecated_classes: list[str] = ["Float64Index", "Int64Index", "UInt64Index"]
93+
deprecated_classes: list[str] = []
9794

9895
# external modules exposed in pandas namespace
9996
modules: list[str] = []

0 commit comments

Comments
 (0)