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)
Comment From: rhshadrach
Hopefully a rare case, but what about the behavior of:
idx1 = pd.Index([1, 2], dtype=object)
idx2 = pd.Index([3, 4])
print(idx1.append(idx2))
I would think this should also be object, as otherwise we get values-dependent behavior.
Comment From: Swati-Sneha
take
Comment From: jorisvandenbossche
I would think this should also be object, as otherwise we get values-dependent behavior.
Indeed, I would also expect object dtype in that case
Comment From: jbrockmendel
+1 for getting rid of dtype inference. want to Just Do It for 3.0?