-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Open
Labels
Dtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsIndexRelated to the Index class or subclassesRelated to the Index class or subclassesStringsString extension data type and string dataString extension data type and string data
Milestone
Description
If you combine two Index objects using append
, if they are both object dtype to start with, it seems we still infer the dtype for the result instead of preserving object dtype:
idx1 = pd.Index(["b", "a"], dtype=object)
idx2 = pd.Index(["c", "d"], dtype=object)
>>> idx1.append(idx2)
Index(['b', 'a', 'c', 'd'], dtype='object')
>>> pd.options.future.infer_string = True
>>> idx1.append(idx2)
Index(['b', 'a', 'c', 'd'], dtype='str') # <-- upcast to string
I would expect that to preserve the dtype of the calling / passed Index (or at least its "common" dtype, which in this case clearly is object dtype)
rhshadrach and jbrockmendel
Metadata
Metadata
Assignees
Labels
Dtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsIndexRelated to the Index class or subclassesRelated to the Index class or subclassesStringsString extension data type and string dataString extension data type and string data