Pandas version checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pandas.

  • [x] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

idx = pd.Index(pd.array([1., 2., 3., 4]))

>>> idx.insert(1, False)
Index([1.0, 0.0, 2.0, 3.0, 4.0], dtype='Float64')

Issue Description

Discovered while adapting tests.indexing.test_coercion tests to nullable dtypes.

Expected Behavior

To be consistent with other behavior this should keep the False as False and cast to object.

Installed Versions

Replace this line with the output of pd.show_versions()

Comment From: kernelism

take

Comment From: kernelism

On initial inspection, this seems to be because dtype compatibility checks were bypassed when dealing with ExtensionArray. This coerces False -> 0.0 without warning.

A workaround is to do something like

pd.Index([1., 2., 3], dtype="object").insert(1, False)

If we need a fix for this, we can add a dtype compatibility check before inserting into ExtensionArray. Should I open a PR?