Skip to content

TST/CLN: Remove makeUInt/Timedelta/RangeIndex #56200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
RangeIndex,
Series,
bdate_range,
timedelta_range,
)
from pandas._testing._io import (
round_trip_localpath,
Expand Down Expand Up @@ -111,10 +112,7 @@
NpDtype,
)

from pandas import (
PeriodIndex,
TimedeltaIndex,
)
from pandas import PeriodIndex
from pandas.core.arrays import ArrowExtensionArray

_N = 30
Expand Down Expand Up @@ -405,17 +403,6 @@ def makeIntIndex(k: int = 10, *, name=None, dtype: Dtype = "int64") -> Index:
return makeNumericIndex(k, name=name, dtype=dtype)


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


def makeRangeIndex(k: int = 10, name=None, **kwargs) -> RangeIndex:
return RangeIndex(0, k, 1, name=name, **kwargs)


def makeFloatIndex(k: int = 10, *, name=None, dtype: Dtype = "float64") -> Index:
dtype = pandas_dtype(dtype)
if not is_float_dtype(dtype):
Expand All @@ -431,12 +418,6 @@ def makeDateIndex(
return DatetimeIndex(dr, name=name, **kwargs)


def makeTimedeltaIndex(
k: int = 10, freq: Frequency = "D", name=None, **kwargs
) -> TimedeltaIndex:
return pd.timedelta_range(start="1 day", periods=k, freq=freq, name=name, **kwargs)


def makePeriodIndex(k: int = 10, name=None, **kwargs) -> PeriodIndex:
dt = datetime(2000, 1, 1)
pi = pd.period_range(start=dt, periods=k, freq="D", name=name, **kwargs)
Expand Down Expand Up @@ -537,7 +518,7 @@ def makeCustomIndex(
"f": makeFloatIndex,
"s": lambda n: Index([f"{i}_{chr(i)}" for i in range(97, 97 + n)]),
"dt": makeDateIndex,
"td": makeTimedeltaIndex,
"td": lambda n: timedelta_range("1 day", periods=n),
"p": makePeriodIndex,
}
idx_func = idx_func_dict.get(idx_type)
Expand Down Expand Up @@ -1027,11 +1008,8 @@ def shares_memory(left, right) -> bool:
"makeNumericIndex",
"makeObjectSeries",
"makePeriodIndex",
"makeRangeIndex",
"makeTimeDataFrame",
"makeTimedeltaIndex",
"makeTimeSeries",
"makeUIntIndex",
"maybe_produces_warning",
"NARROW_NP_DTYPES",
"NP_NAT_OBJECTS",
Expand Down
14 changes: 8 additions & 6 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
Interval,
IntervalIndex,
Period,
RangeIndex,
Series,
Timedelta,
Timestamp,
timedelta_range,
)
import pandas._testing as tm
from pandas.core import ops
Expand Down Expand Up @@ -614,16 +616,16 @@ def _create_mi_with_dt64tz_level():
"datetime": tm.makeDateIndex(100),
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),
"period": tm.makePeriodIndex(100),
"timedelta": tm.makeTimedeltaIndex(100),
"range": tm.makeRangeIndex(100),
"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"),
"uint8": tm.makeUIntIndex(100, dtype="uint8"),
"uint16": tm.makeUIntIndex(100, dtype="uint16"),
"uint32": tm.makeUIntIndex(100, dtype="uint32"),
"uint64": tm.makeUIntIndex(100, dtype="uint64"),
"uint8": Index(np.arange(100), dtype="uint8"),
"uint16": Index(np.arange(100), dtype="uint16"),
"uint32": Index(np.arange(100), dtype="uint32"),
"uint64": Index(np.arange(100), dtype="uint64"),
"float32": tm.makeFloatIndex(100, dtype="float32"),
"float64": tm.makeFloatIndex(100, dtype="float64"),
"bool-object": Index([True, False] * 5, dtype=object),
Expand Down
31 changes: 16 additions & 15 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
Categorical,
CategoricalDtype,
DataFrame,
DatetimeIndex,
Index,
PeriodIndex,
RangeIndex,
Series,
Timestamp,
date_range,
Expand Down Expand Up @@ -598,7 +601,7 @@ def test_sem(self, datetime_frame):
"C": [1.0],
"D": ["a"],
"E": Categorical(["a"], categories=["a"]),
"F": pd.DatetimeIndex(["2000-01-02"], dtype="M8[ns]"),
"F": DatetimeIndex(["2000-01-02"], dtype="M8[ns]"),
"G": to_timedelta(["1 days"]),
},
),
Expand All @@ -610,7 +613,7 @@ def test_sem(self, datetime_frame):
"C": [np.nan],
"D": np.array([np.nan], dtype=object),
"E": Categorical([np.nan], categories=["a"]),
"F": pd.DatetimeIndex([pd.NaT], dtype="M8[ns]"),
"F": DatetimeIndex([pd.NaT], dtype="M8[ns]"),
"G": to_timedelta([pd.NaT]),
},
),
Expand All @@ -621,7 +624,7 @@ def test_sem(self, datetime_frame):
"I": [8, 9, np.nan, np.nan],
"J": [1, np.nan, np.nan, np.nan],
"K": Categorical(["a", np.nan, np.nan, np.nan], categories=["a"]),
"L": pd.DatetimeIndex(
"L": DatetimeIndex(
["2000-01-02", "NaT", "NaT", "NaT"], dtype="M8[ns]"
),
"M": to_timedelta(["1 days", "nan", "nan", "nan"]),
Expand All @@ -635,7 +638,7 @@ def test_sem(self, datetime_frame):
"I": [8, 9, np.nan, np.nan],
"J": [1, np.nan, np.nan, np.nan],
"K": Categorical([np.nan, "a", np.nan, np.nan], categories=["a"]),
"L": pd.DatetimeIndex(
"L": DatetimeIndex(
["NaT", "2000-01-02", "NaT", "NaT"], dtype="M8[ns]"
),
"M": to_timedelta(["nan", "1 days", "nan", "nan"]),
Expand All @@ -652,15 +655,13 @@ def test_mode_dropna(self, dropna, expected):
"C": [1, np.nan, np.nan, np.nan],
"D": [np.nan, np.nan, "a", np.nan],
"E": Categorical([np.nan, np.nan, "a", np.nan]),
"F": pd.DatetimeIndex(
["NaT", "2000-01-02", "NaT", "NaT"], dtype="M8[ns]"
),
"F": DatetimeIndex(["NaT", "2000-01-02", "NaT", "NaT"], dtype="M8[ns]"),
"G": to_timedelta(["1 days", "nan", "nan", "nan"]),
"H": [8, 8, 9, 9],
"I": [9, 9, 8, 8],
"J": [1, 1, np.nan, np.nan],
"K": Categorical(["a", np.nan, "a", np.nan]),
"L": pd.DatetimeIndex(
"L": DatetimeIndex(
["2000-01-02", "2000-01-02", "NaT", "NaT"], dtype="M8[ns]"
),
"M": to_timedelta(["1 days", "nan", "1 days", "nan"]),
Expand Down Expand Up @@ -830,15 +831,15 @@ def test_sum_corner(self):
@pytest.mark.parametrize(
"index",
[
tm.makeRangeIndex(0),
tm.makeDateIndex(0),
tm.makeNumericIndex(0, dtype=int),
tm.makeNumericIndex(0, dtype=float),
tm.makeDateIndex(0, freq="ME"),
tm.makePeriodIndex(0),
RangeIndex(0),
DatetimeIndex([]),
Index([], dtype=np.int64),
Index([], dtype=np.float64),
DatetimeIndex([], freq="ME"),
PeriodIndex([], freq="D"),
],
)
def test_axis_1_empty(self, all_reductions, index, using_array_manager):
def test_axis_1_empty(self, all_reductions, index):
df = DataFrame(columns=["a"], index=index)
result = getattr(df, all_reductions)(axis=1)
if all_reductions in ("any", "all"):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/indexes/datetimelike_/test_equals.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TimedeltaIndex,
date_range,
period_range,
timedelta_range,
)
import pandas._testing as tm

Expand Down Expand Up @@ -141,7 +142,7 @@ def test_not_equals_bday(self, freq):
class TestTimedeltaIndexEquals(EqualsTests):
@pytest.fixture
def index(self):
return tm.makeTimedeltaIndex(10)
return timedelta_range("1 day", periods=10)

def test_equals2(self):
# GH#13107
Expand Down
17 changes: 11 additions & 6 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
TimedeltaIndex,
date_range,
period_range,
timedelta_range,
)
import pandas._testing as tm
from pandas.core.indexes.api import (
Expand Down Expand Up @@ -92,7 +93,7 @@ def test_constructor_copy(self, index):
name="Green Eggs & Ham",
), # DTI with tz
date_range("2015-01-01 10:00", freq="D", periods=3), # DTI no tz
pd.timedelta_range("1 days", freq="D", periods=3), # td
timedelta_range("1 days", freq="D", periods=3), # td
period_range("2015-01-01", freq="D", periods=3), # period
],
)
Expand Down Expand Up @@ -122,7 +123,7 @@ def test_constructor_from_index_dtlike(self, cast_as_obj, index):
date_range("2015-01-01 10:00", freq="D", periods=3, tz="US/Eastern"),
True,
), # datetimetz
(pd.timedelta_range("1 days", freq="D", periods=3), False), # td
(timedelta_range("1 days", freq="D", periods=3), False), # td
(period_range("2015-01-01", freq="D", periods=3), False), # period
],
)
Expand Down Expand Up @@ -267,7 +268,7 @@ def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, klass):
@pytest.mark.parametrize("attr", ["values", "asi8"])
@pytest.mark.parametrize("klass", [Index, TimedeltaIndex])
def test_constructor_dtypes_timedelta(self, attr, klass):
index = pd.timedelta_range("1 days", periods=5)
index = timedelta_range("1 days", periods=5)
index = index._with_freq(None) # won't be preserved by constructors
dtype = index.dtype

Expand Down Expand Up @@ -526,10 +527,14 @@ def test_map_with_tuples_mi(self):
tm.assert_index_equal(reduced_index, Index(first_level))

@pytest.mark.parametrize(
"attr", ["makeDateIndex", "makePeriodIndex", "makeTimedeltaIndex"]
"index",
[
date_range("2020-01-01", freq="D", periods=10),
period_range("2020-01-01", freq="D", periods=10),
timedelta_range("1 day", periods=10),
],
)
def test_map_tseries_indices_return_index(self, attr):
index = getattr(tm, attr)(10)
def test_map_tseries_indices_return_index(self, index):
expected = Index([1] * 10)
result = index.map(lambda x: 1)
tm.assert_index_equal(expected, result)
Expand Down
15 changes: 6 additions & 9 deletions pandas/tests/indexes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,16 @@ def test_union_different_types(index_flat, index_flat2, request):


@pytest.mark.parametrize(
"idx_fact1,idx_fact2",
"idx1,idx2",
[
(tm.makeIntIndex, tm.makeRangeIndex),
(tm.makeFloatIndex, tm.makeIntIndex),
(tm.makeFloatIndex, tm.makeRangeIndex),
(tm.makeFloatIndex, tm.makeUIntIndex),
(Index(np.arange(5), dtype=np.int64), RangeIndex(5)),
(Index(np.arange(5), dtype=np.float64), Index(np.arange(5), dtype=np.int64)),
(Index(np.arange(5), dtype=np.float64), RangeIndex(5)),
(Index(np.arange(5), dtype=np.float64), Index(np.arange(5), dtype=np.uint64)),
],
)
def test_compatible_inconsistent_pairs(idx_fact1, idx_fact2):
def test_compatible_inconsistent_pairs(idx1, idx2):
# GH 23525
idx1 = idx_fact1(10)
idx2 = idx_fact2(20)

res1 = idx1.union(idx2)
res2 = idx2.union(idx1)

Expand Down
31 changes: 17 additions & 14 deletions pandas/tests/indexing/test_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ def test_scalar_with_mixed(self, indexer_sl):
expected = 3
assert result == expected

@pytest.mark.parametrize("index_func", [tm.makeIntIndex, tm.makeRangeIndex])
def test_scalar_integer(self, index_func, frame_or_series, indexer_sl):
@pytest.mark.parametrize(
"index", [Index(np.arange(5), dtype=np.int64), RangeIndex(5)]
)
def test_scalar_integer(self, index, frame_or_series, indexer_sl):
getitem = indexer_sl is not tm.loc

# test how scalar float indexers work on int indexes

# integer index
i = index_func(5)
i = index
obj = gen_obj(frame_or_series, i)

# coerce to equal int
Expand Down Expand Up @@ -169,11 +171,12 @@ def compare(x, y):
result = indexer_sl(s2)[3]
compare(result, expected)

@pytest.mark.parametrize("index_func", [tm.makeIntIndex, tm.makeRangeIndex])
def test_scalar_integer_contains_float(self, index_func, frame_or_series):
@pytest.mark.parametrize(
"index", [Index(np.arange(5), dtype=np.int64), RangeIndex(5)]
)
def test_scalar_integer_contains_float(self, index, frame_or_series):
# contains
# integer index
index = index_func(5)
obj = gen_obj(frame_or_series, index)

# coerce to equal int
Expand Down Expand Up @@ -348,11 +351,11 @@ def test_integer_positional_indexing(self, idx):
with pytest.raises(TypeError, match=msg):
s.iloc[idx]

@pytest.mark.parametrize("index_func", [tm.makeIntIndex, tm.makeRangeIndex])
def test_slice_integer_frame_getitem(self, index_func):
@pytest.mark.parametrize(
"index", [Index(np.arange(5), dtype=np.int64), RangeIndex(5)]
)
def test_slice_integer_frame_getitem(self, index):
# similar to above, but on the getitem dim (of a DataFrame)
index = index_func(5)

s = DataFrame(np.random.default_rng(2).standard_normal((5, 2)), index=index)

# getitem
Expand Down Expand Up @@ -403,11 +406,11 @@ def test_slice_integer_frame_getitem(self, index_func):
s[idx]

@pytest.mark.parametrize("idx", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)])
@pytest.mark.parametrize("index_func", [tm.makeIntIndex, tm.makeRangeIndex])
def test_float_slice_getitem_with_integer_index_raises(self, idx, index_func):
@pytest.mark.parametrize(
"index", [Index(np.arange(5), dtype=np.int64), RangeIndex(5)]
)
def test_float_slice_getitem_with_integer_index_raises(self, idx, index):
# similar to above, but on the getitem dim (of a DataFrame)
index = index_func(5)

s = DataFrame(np.random.default_rng(2).standard_normal((5, 2)), index=index)

# setitem
Expand Down
Loading