-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
BUG/API: Index constructor does not enforce specified dtype #21311
Comments
xref #21254 (comment) Meant to create an issue similar to this for the In [2]: cat = pd.Categorical([pd.Interval(0, 1), pd.Interval(1, 2), pd.Interval(0, 1)])
In [3]: pd.Index(cat, dtype='interval')
Out[3]: CategoricalIndex([(0, 1], (1, 2], (0, 1]], categories=[(0, 1], (1, 2]], ordered=False, dtype='category') This happens because the pandas/pandas/core/indexes/base.py Lines 262 to 273 in c85ab08
The code above could be restructured so that the Not immediately sure what the fix for other scenarios entails, as |
Code Sample, a copy-pastable example if possible
Manually specifying a dtype does not garantuee the output is in that dtype. Eg with Series if incompatible data is passed, an error is raised, while for Index it just silently outputs another dtype:
The text was updated successfully, but these errors were encountered: