Skip to content

Commit

Permalink
DEPR: remove Int64Index, UInt64Index, Float64Index from public namesp…
Browse files Browse the repository at this point in the history
…ace (pandas-dev#49670)

* DEPR: remove Int64Index, UInt64Index, Float64Index

* fix isort

* fix stuff

* fix pyright & mypy

* fix isort

* fix mypy

Co-authored-by: Terji Petersen <terjipetersen@Terjis-Air.fritz.box>
  • Loading branch information
2 people authored and mliu08 committed Nov 27, 2022
1 parent da48832 commit 341ab8f
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 81 deletions.
20 changes: 10 additions & 10 deletions asv_bench/benchmarks/hash_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def time_unique(self, exponent):
class NumericSeriesIndexing:

params = [
(pd.Int64Index, pd.UInt64Index, pd.Float64Index),
(np.int64, np.uint64, np.float64),
(10**4, 10**5, 5 * 10**5, 10**6, 5 * 10**6),
]
param_names = ["index_dtype", "N"]
param_names = ["dtype", "N"]

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

def time_loc_slice(self, index, N):
Expand All @@ -75,15 +75,15 @@ def time_loc_slice(self, index, N):
class NumericSeriesIndexingShuffled:

params = [
(pd.Int64Index, pd.UInt64Index, pd.Float64Index),
(np.int64, np.uint64, np.float64),
(10**4, 10**5, 5 * 10**5, 10**6, 5 * 10**6),
]
param_names = ["index_dtype", "N"]
param_names = ["dtype", "N"]

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

def time_loc_slice(self, index, N):
Expand Down
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/index_cached_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup(self, index_type):
elif index_type == "DatetimeIndex":
self.idx = pd.date_range("1/1/2000", freq="T", periods=N)
elif index_type == "Int64Index":
self.idx = pd.Index(range(N))
self.idx = pd.Index(range(N), dtype="int64")
elif index_type == "PeriodIndex":
self.idx = pd.period_range("1/1/2000", freq="T", periods=N)
elif index_type == "RangeIndex":
Expand All @@ -40,9 +40,9 @@ def setup(self, index_type):
elif index_type == "TimedeltaIndex":
self.idx = pd.TimedeltaIndex(range(N))
elif index_type == "Float64Index":
self.idx = pd.Float64Index(range(N))
self.idx = pd.Index(range(N), dtype="float64")
elif index_type == "UInt64Index":
self.idx = pd.UInt64Index(range(N))
self.idx = pd.Index(range(N), dtype="uint64")
elif index_type == "CategoricalIndex":
self.idx = pd.CategoricalIndex(range(N), range(N))
else:
Expand Down
5 changes: 2 additions & 3 deletions asv_bench/benchmarks/index_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from pandas import (
DatetimeIndex,
Float64Index,
Index,
IntervalIndex,
MultiIndex,
Expand Down Expand Up @@ -202,8 +201,8 @@ class Float64IndexMethod:
# GH 13166
def setup(self):
N = 100_000
a = np.arange(N)
self.ind = Float64Index(a * 4.8000000418824129e-08)
a = np.arange(N, dtype=np.float64)
self.ind = Index(a * 4.8000000418824129e-08)

def time_get_loc(self):
self.ind.get_loc(0)
Expand Down
30 changes: 14 additions & 16 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
from pandas import (
CategoricalIndex,
DataFrame,
Float64Index,
Int64Index,
Index,
IntervalIndex,
MultiIndex,
Series,
UInt64Index,
concat,
date_range,
option_context,
Expand All @@ -30,17 +28,17 @@
class NumericSeriesIndexing:

params = [
(Int64Index, UInt64Index, Float64Index),
(np.int64, np.uint64, np.float64),
("unique_monotonic_inc", "nonunique_monotonic_inc"),
]
param_names = ["index_dtype", "index_structure"]
param_names = ["dtype", "index_structure"]

def setup(self, index, index_structure):
def setup(self, dtype, index_structure):
N = 10**6
indices = {
"unique_monotonic_inc": index(range(N)),
"nonunique_monotonic_inc": index(
list(range(55)) + [54] + list(range(55, N - 1))
"unique_monotonic_inc": Index(range(N), dtype=dtype),
"nonunique_monotonic_inc": Index(
list(range(55)) + [54] + list(range(55, N - 1)), dtype=dtype
),
}
self.data = Series(np.random.rand(N), index=indices[index_structure])
Expand Down Expand Up @@ -159,17 +157,17 @@ def time_boolean_rows_boolean(self):
class DataFrameNumericIndexing:

params = [
(Int64Index, UInt64Index, Float64Index),
(np.int64, np.uint64, np.float64),
("unique_monotonic_inc", "nonunique_monotonic_inc"),
]
param_names = ["index_dtype", "index_structure"]
param_names = ["dtype", "index_structure"]

def setup(self, index, index_structure):
def setup(self, dtype, index_structure):
N = 10**5
indices = {
"unique_monotonic_inc": index(range(N)),
"nonunique_monotonic_inc": index(
list(range(55)) + [54] + list(range(55, N - 1))
"unique_monotonic_inc": Index(range(N), dtype=dtype),
"nonunique_monotonic_inc": Index(
list(range(55)) + [54] + list(range(55, N - 1)), dtype=dtype
),
}
self.idx_dupe = np.array(range(30)) * 99
Expand Down Expand Up @@ -201,7 +199,7 @@ class Take:
def setup(self, index):
N = 100000
indexes = {
"int": Int64Index(np.arange(N)),
"int": Index(np.arange(N), dtype=np.int64),
"datetime": date_range("2011-01-01", freq="S", periods=N),
}
index = indexes[index]
Expand Down
3 changes: 0 additions & 3 deletions doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ Numeric Index
:template: autosummary/class_without_autosummary.rst

RangeIndex
Int64Index
UInt64Index
Float64Index

.. We need this autosummary so that the methods are generated.
.. Separate block, since they aren't classes.
Expand Down
32 changes: 0 additions & 32 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,38 +183,6 @@
__git_version__ = v.get("full-revisionid")
del get_versions, v

# GH 27101
__deprecated_num_index_names = ["Float64Index", "Int64Index", "UInt64Index"]


def __dir__() -> list[str]:
# GH43028
# Int64Index etc. are deprecated, but we still want them to be available in the dir.
# Remove in Pandas 2.0, when we remove Int64Index etc. from the code base.
return list(globals().keys()) + __deprecated_num_index_names


def __getattr__(name):
import warnings

if name in __deprecated_num_index_names:
warnings.warn(
f"pandas.{name} is deprecated "
"and will be removed from pandas in a future version. "
"Use pandas.Index with the appropriate dtype instead.",
FutureWarning,
stacklevel=2,
)
from pandas.core.api import Float64Index, Int64Index, UInt64Index

return {
"Float64Index": Float64Index,
"Int64Index": Int64Index,
"UInt64Index": UInt64Index,
}[name]

raise AttributeError(f"module 'pandas' has no attribute '{name}'")


# module level doc-string
__doc__ = """
Expand Down
3 changes: 2 additions & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
Series,
Timedelta,
Timestamp,
compat,
)
import pandas._testing as tm
from pandas.core import ops
Expand All @@ -79,7 +80,7 @@
has_pyarrow = True

zoneinfo = None
if pd.compat.PY39:
if compat.PY39:
# Import "zoneinfo" could not be resolved (reportMissingImports)
import zoneinfo # type: ignore[no-redef]

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,9 @@ def _addsub_object_array(self, other: np.ndarray, op):

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

result = pd_array(res_values.ravel())
result = extract_array(result, extract_numpy=True).reshape(self.shape)
ext_arr = pd_array(res_values.ravel())
result = cast(np.ndarray, extract_array(ext_arr, extract_numpy=True))
result = result.reshape(self.shape)
return result

def _time_shift(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@

if TYPE_CHECKING:
from pandas import (
ExtensionArray,
Index,
Series,
)
from pandas.core.arrays.base import ExtensionArray


def array(
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/dtypes/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
CategoricalIndex,
DataFrame,
DatetimeIndex,
Float64Index,
Index,
Int64Index,
IntervalIndex,
MultiIndex,
PeriodIndex,
RangeIndex,
Series,
TimedeltaIndex,
UInt64Index,
)
from pandas.core.arrays import (
DatetimeArray,
Expand All @@ -32,6 +29,11 @@
TimedeltaArray,
)
from pandas.core.generic import NDFrame
from pandas.core.indexes.api import (
Float64Index,
Int64Index,
UInt64Index,
)


# define abstract base classes to enable isinstance type checking on our
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from pandas.core.tools.times import to_time

if TYPE_CHECKING:
from pandas import (
from pandas.core.api import (
DataFrame,
Float64Index,
PeriodIndex,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
)

if TYPE_CHECKING:
from pandas import Float64Index
from pandas.core.api import Float64Index


T = TypeVar("T", bound="BaseArrayManager")
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
from pandas.core.indexers import check_setitem_lengths

if TYPE_CHECKING:
from pandas import (
from pandas.core.api import (
Float64Index,
Index,
)
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ class TestPDApi(Base):
"DatetimeIndex",
"ExcelFile",
"ExcelWriter",
"Float64Index",
"Flags",
"Grouper",
"HDFStore",
"Index",
"Int64Index",
"MultiIndex",
"Period",
"PeriodIndex",
"RangeIndex",
"UInt64Index",
"Series",
"SparseDtype",
"StringDtype",
Expand Down Expand Up @@ -93,7 +90,7 @@ class TestPDApi(Base):
]

# these are already deprecated; awaiting removal
deprecated_classes: list[str] = ["Float64Index", "Int64Index", "UInt64Index"]
deprecated_classes: list[str] = []

# external modules exposed in pandas namespace
modules: list[str] = []
Expand Down

0 comments on commit 341ab8f

Please sign in to comment.