BUG/API: Index constructor does not enforce specified dtype · Issue #21311 · pandas-dev/pandas (original) (raw)
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')