-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Labels
BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsIndexRelated to the Index class or subclassesRelated to the Index class or subclasses
Milestone
Description
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:
In [11]: pd.Series(['a', 'b', 'c'], dtype='int64')
...
ValueError: invalid literal for int() with base 10: 'a'
In [12]: pd.Index(['a', 'b', 'c'], dtype='int64')
Out[12]: Index(['a', 'b', 'c'], dtype='object')
Metadata
Metadata
Assignees
Labels
BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsIndexRelated to the Index class or subclassesRelated to the Index class or subclasses
Activity
jschendel commentedon Jun 4, 2018
xref #21254 (comment)
Meant to create an issue similar to this for the
Categorical
-->Interval
case:This happens because the
Index
code is structured so that categorical takes precedence over interval:pandas/pandas/core/indexes/base.py
Lines 262 to 273 in c85ab08
The code above could be restructured so that the
dtype
argument, if present, takes precedence over the type ofdata
.Not immediately sure what the fix for other scenarios entails, as
Categorical
andInterval
are a bit of a special case.