-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Needs a whatsnew note in v3.0.0.rst
and a unit test.
Also could you fix this for float types too?
Can you give me an example for float type with expected results? Thank you! |
I have added my implementations for supporting float types. But I see in base.py that pandas doesn't support float16 data types. Should I convert them to float64 or just let pandas thow Exception? base.py: elif dtype == np.float16:
# float16 not supported (no indexing engine)
raise NotImplementedError("float16 indexes are not supported") For example: interval_index_float = pd.interval_range(start=np.float32(0.0), end=np.float32(0.6), freq=0.5, closed="left")
print(interval_index_float) Gives:
But: interval_index_float = pd.interval_range(start=np.float16(0.0), end=np.float16(0.6), freq=0.5, closed="left")
print(interval_index_float) will raise:
I have added implementation to ignore float16 like this and checked-in my changes. If you want to let it throw an exception let me know! My implementation: if isinstance(start, float | np.float16) or isinstance(
end, float | np.float16
):
dtype = np.dtype("float64")
else:
dtype = start.dtype if start.dtype == end.dtype else np.dtype("float64")
breaks = np.arange(start, end + (freq * 0.1), freq, dtype=dtype) Current implementation safely returns float64 if it finds float16, Just like current main release! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completed as you asked!
Changes have been completed as you asked! |
Co-authored-by: Matthew Roeschke <[email protected]>
Co-authored-by: Matthew Roeschke <[email protected]>
Thanks @VISWESWARAN1998 |
You are most welcome @mroeschke ! |
…n interval… (pandas-dev#57399) * Fix for issue pandas-dev#57268 - ENH: Preserve input start/end type in interval_range * issue pandas-dev#57268 - github actions resolution * Use generated datatype from breaks * Ruff - Pre-commit issue fix * Fix for issue pandas-dev#57268 - floating point support * int - float dtype compatability * whatsnew documentation update * OS based varaible access * Fixing failed unit test cases * pytest - interval passsed * Python backwards compatability * Pytest * Fixing PyLint and mypy issues * dtype specification * Conditional statement simplification * remove redundant code blocks * Changing whatsnew to interval section * Passing expected in parameterize * Update doc/source/whatsnew/v3.0.0.rst Co-authored-by: Matthew Roeschke <[email protected]> * Update pandas/core/indexes/interval.py Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Matthew Roeschke <[email protected]>
…_range
start
/end
type ininterval_range
#57268doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.