Skip to content
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ Interval
- :meth:`Index.is_monotonic_decreasing`, :meth:`Index.is_monotonic_increasing`, and :meth:`Index.is_unique` could incorrectly be ``False`` for an ``Index`` created from a slice of another ``Index``. (:issue:`57911`)
- Bug in :class:`Index`, :class:`Series`, :class:`DataFrame` constructors when given a sequence of :class:`Interval` subclass objects casting them to :class:`Interval` (:issue:`46945`)
- Bug in :func:`interval_range` where start and end numeric types were always cast to 64 bit (:issue:`57268`)
- Bug in :func:`pandas.interval_range` incorrectly inferring ``int64`` dtype when ``np.float32`` and ``int`` are used for ``start`` and ``freq`` (:issue:`58964`)
- Bug in :meth:`IntervalIndex.get_indexer` and :meth:`IntervalIndex.drop` when one of the sides of the index is non-unique (:issue:`52245`)
- Construction of :class:`IntervalArray` and :class:`IntervalIndex` from arrays with mismatched signed/unsigned integer dtypes (e.g., ``int64`` and ``uint64``) now raises a :exc:`TypeError` instead of proceeding silently. (:issue:`55715`)

Expand Down
12 changes: 6 additions & 6 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,17 +1420,17 @@ def interval_range(
dtype: np.dtype = np.dtype("int64")
if com.all_not_none(start, end, freq):
if (
isinstance(start, (float, np.float16))
or isinstance(end, (float, np.float16))
or isinstance(freq, (float, np.float16))
):
dtype = np.dtype("float64")
elif (
isinstance(start, (np.integer, np.floating))
and isinstance(end, (np.integer, np.floating))
and start.dtype == end.dtype
):
dtype = start.dtype
elif (
isinstance(start, (float, np.floating))
or isinstance(end, (float, np.floating))
or isinstance(freq, (float, np.floating))
):
dtype = np.dtype("float64")
# 0.1 ensures we capture end
breaks = np.arange(start, end + (freq * 0.1), freq)
breaks = maybe_downcast_numeric(breaks, dtype)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexes/interval/test_interval_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,11 @@ def test_float_freq(self):
result = interval_range(0, 1, freq=0.6)
expected = IntervalIndex.from_breaks([0, 0.6])
tm.assert_index_equal(result, expected)

def test_interval_range_float32_start_int_freq(self):
# GH 58964
result = interval_range(start=np.float32(0), end=2, freq=1)
expected = IntervalIndex.from_tuples(
[(0.0, 1.0), (1.0, 2.0)], dtype="interval[float64, right]"
)
tm.assert_index_equal(result, expected)
Loading