From 54c880c7ea2491cc55be9c290dbd63af30f118cb Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Sun, 9 Nov 2025 08:41:50 +0530 Subject: [PATCH 1/5] Fix: interval_range ignores dtype of start --- pandas/core/indexes/interval.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index a4a6230337add..6c3d3bce60e1a 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1423,6 +1423,9 @@ def interval_range( isinstance(start, (float, np.float16)) or isinstance(end, (float, np.float16)) or isinstance(freq, (float, np.float16)) + or isinstance(start, (float, np.float32)) + or isinstance(end, (float, np.float32)) + or isinstance(freq, (float, np.float32)) ): dtype = np.dtype("float64") elif ( From 8f5b32dccabeab1706f7b1ab0480a5634e2fd6e9 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Sun, 9 Nov 2025 08:44:45 +0530 Subject: [PATCH 2/5] Made modifications efficient --- pandas/core/indexes/interval.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 6c3d3bce60e1a..e1408e3e41762 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1420,12 +1420,9 @@ 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)) - or isinstance(start, (float, np.float32)) - or isinstance(end, (float, np.float32)) - or isinstance(freq, (float, np.float32)) + isinstance(start, (float, np.floating)) + or isinstance(end, (float, np.floating)) + or isinstance(freq, (float, np.floating)) ): dtype = np.dtype("float64") elif ( From 2dd0d27ba8dabf5d3ff5fd9aee51c87096d79ccf Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Sun, 9 Nov 2025 08:54:02 +0530 Subject: [PATCH 3/5] Ruff Formatting --- pandas/tests/indexes/interval/test_interval_range.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/interval/test_interval_range.py b/pandas/tests/indexes/interval/test_interval_range.py index 5252b85ad8d0e..8cfc9884233a1 100644 --- a/pandas/tests/indexes/interval/test_interval_range.py +++ b/pandas/tests/indexes/interval/test_interval_range.py @@ -225,7 +225,7 @@ def test_float_subtype(self, start, end, freq): [ (np.int8(1), np.int8(10), np.dtype("int8")), (np.int8(1), np.float16(10), np.dtype("float64")), - (np.float32(1), np.float32(10), np.dtype("float32")), + (np.float32(1), np.float32(10), np.dtype("float64")), (1, 10, np.dtype("int64")), (1, 10.0, np.dtype("float64")), ], @@ -380,3 +380,13 @@ 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 + from pandas.testing import assert_index_equal + + 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]" + ) + assert_index_equal(result, expected) From 7e068440a36494435e551704d675f12a4a0bee77 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Sun, 9 Nov 2025 09:04:17 +0530 Subject: [PATCH 4/5] Added changelog --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 65982ecdb810c..eb25f8ab34ca0 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -1125,6 +1125,7 @@ Strings 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 :func:`pandas.interval_range` incorrectly inferring ``int64`` dtype when ``np.float32`` and ``int`` are used for ``start`` and ``freq`` (:gh:`58964`) - 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 :meth:`IntervalIndex.get_indexer` and :meth:`IntervalIndex.drop` when one of the sides of the index is non-unique (:issue:`52245`) From bf70dcf1a436bf0fecc2fdcdd5bafc840991219a Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Sun, 9 Nov 2025 09:24:31 +0530 Subject: [PATCH 5/5] Fixing changelog --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index eb25f8ab34ca0..d0a2ab14d8146 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -1125,9 +1125,9 @@ Strings 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 :func:`pandas.interval_range` incorrectly inferring ``int64`` dtype when ``np.float32`` and ``int`` are used for ``start`` and ``freq`` (:gh:`58964`) - 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`)