Skip to content

Fix for issue #57268 - ENH: Preserve input start/end type in interval… #57399

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 21 commits into from
Feb 15, 2024
Merged
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
12 changes: 11 additions & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,19 @@ def interval_range(
# error: Argument 1 to "maybe_downcast_numeric" has incompatible type
# "Union[ndarray[Any, Any], TimedeltaIndex, DatetimeIndex]";
# expected "ndarray[Any, Any]" [
if isinstance(start, int) or isinstance(end, int):
dtype = np.dtype("int64")
else:
dtype = start.dtype if start.dtype == end.dtype else np.dtype("int64")
breaks = maybe_downcast_numeric(
breaks, # type: ignore[arg-type]
np.dtype("int64"),
dtype,
)
return IntervalIndex.from_breaks(
breaks,
name=name,
closed=closed,
dtype=IntervalDtype(subtype=breaks.dtype, closed=closed),
)
else:
# delegate to the appropriate range function
Expand Down