Skip to content

Commit

Permalink
Remove makeIntIndex/makeNumericIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Nov 28, 2023
1 parent 00079bc commit 2a781d7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
30 changes: 0 additions & 30 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

from pandas.core.dtypes.common import (
is_sequence,
is_signed_integer_dtype,
is_string_dtype,
is_unsigned_integer_dtype,
pandas_dtype,
)

import pandas as pd
Expand Down Expand Up @@ -351,31 +348,6 @@ def getCols(k) -> str:
return string.ascii_uppercase[:k]


def makeNumericIndex(k: int = 10, *, name=None, dtype: Dtype | None) -> Index:
dtype = pandas_dtype(dtype)
assert isinstance(dtype, np.dtype)

if dtype.kind in "iu":
values = np.arange(k, dtype=dtype)
if is_unsigned_integer_dtype(dtype):
values += 2 ** (dtype.itemsize * 8 - 1)
elif dtype.kind == "f":
values = np.random.default_rng(2).random(k) - np.random.default_rng(2).random(1)
values.sort()
values = values * (10 ** np.random.default_rng(2).integers(0, 9))
else:
raise NotImplementedError(f"wrong dtype {dtype}")

return Index(values, dtype=dtype, name=name)


def makeIntIndex(k: int = 10, *, name=None, dtype: Dtype = "int64") -> Index:
dtype = pandas_dtype(dtype)
if not is_signed_integer_dtype(dtype):
raise TypeError(f"Wrong dtype {dtype}")
return makeNumericIndex(k, name=name, dtype=dtype)


def makeDateIndex(
k: int = 10, freq: Frequency = "B", name=None, **kwargs
) -> DatetimeIndex:
Expand Down Expand Up @@ -962,8 +934,6 @@ def shares_memory(left, right) -> bool:
"makeCustomIndex",
"makeDataFrame",
"makeDateIndex",
"makeIntIndex",
"makeNumericIndex",
"makeObjectSeries",
"makeTimeDataFrame",
"makeTimeSeries",
Expand Down
16 changes: 10 additions & 6 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ def _create_mi_with_dt64tz_level():
"period": period_range("2020-01-01", periods=100, freq="D"),
"timedelta": timedelta_range(start="1 day", periods=100, freq="D"),
"range": RangeIndex(100),
"int8": tm.makeIntIndex(100, dtype="int8"),
"int16": tm.makeIntIndex(100, dtype="int16"),
"int32": tm.makeIntIndex(100, dtype="int32"),
"int64": tm.makeIntIndex(100, dtype="int64"),
"int8": Index(np.arange(100), dtype="int8"),
"int16": Index(np.arange(100), dtype="int16"),
"int32": Index(np.arange(100), dtype="int32"),
"int64": Index(np.arange(100), dtype="int64"),
"uint8": Index(np.arange(100), dtype="uint8"),
"uint16": Index(np.arange(100), dtype="uint16"),
"uint32": Index(np.arange(100), dtype="uint32"),
Expand All @@ -632,8 +632,12 @@ def _create_mi_with_dt64tz_level():
"float64": Index(np.arange(100), dtype="float64"),
"bool-object": Index([True, False] * 5, dtype=object),
"bool-dtype": Index(np.random.default_rng(2).standard_normal(10) < 0),
"complex64": tm.makeNumericIndex(100, dtype="float64").astype("complex64"),
"complex128": tm.makeNumericIndex(100, dtype="float64").astype("complex128"),
"complex64": Index(
np.arange(100, dtype="complex64") + 1.0j * np.arange(100, dtype="complex64")
),
"complex128": Index(
np.arange(100, dtype="complex128") + 1.0j * np.arange(100, dtype="complex128")
),
"categorical": CategoricalIndex(list("abcd") * 25),
"interval": IntervalIndex.from_breaks(np.linspace(0, 100, num=101)),
"empty": Index([]),
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ def test_map_with_tuples(self):

# Test that returning a single tuple from an Index
# returns an Index.
index = tm.makeIntIndex(3)
result = tm.makeIntIndex(3).map(lambda x: (x,))
index = Index(np.arange(3), dtype=np.int64)
result = index.map(lambda x: (x,))
expected = Index([(i,) for i in index])
tm.assert_index_equal(result, expected)

Expand Down Expand Up @@ -555,7 +555,7 @@ def test_map_tseries_indices_accsr_return_index(self):
def test_map_dictlike_simple(self, mapper):
# GH 12756
expected = Index(["foo", "bar", "baz"])
index = tm.makeIntIndex(3)
index = Index(np.arange(3), dtype=np.int64)
result = index.map(mapper(expected.values, index))
tm.assert_index_equal(result, expected)

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def test_setitem_slice_integers(self):

def test_setitem_slicestep(self):
# caught this bug when writing tests
series = Series(tm.makeIntIndex(20).astype(float), index=tm.makeIntIndex(20))
series = Series(
np.arange(20, dtype=np.float64), index=np.arange(20, dtype=np.int64)
)

series[::2] = 0
assert (series[::2] == 0).all()
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/series/methods/test_combine_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_combine_first_name(self, datetime_series):
assert result.name == datetime_series.name

def test_combine_first(self):
values = tm.makeIntIndex(20).values.astype(float)
series = Series(values, index=tm.makeIntIndex(20))
values = np.arange(20, dtype=np.float64)
series = Series(values, index=np.arange(20, dtype=np.int64))

series_copy = series * 2
series_copy[::2] = np.nan
Expand Down

0 comments on commit 2a781d7

Please sign in to comment.