diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 7da6d43c732a9..f76e0d1458731 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -378,6 +378,15 @@ Performance improvements Bug fixes ~~~~~~~~~ +- Fixed bug in :class:`Index` Index constructor was not converting FLS to object. (:issue:`57645`) +- Fixed bug in :class:`SparseDtype` for equal comparison with na fill value. (:issue:`54770`) +- Fixed bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`) +- Fixed bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`) +- Fixed bug in :meth:`DataFrame.update` bool dtype being converted to object (:issue:`55509`) +- Fixed bug in :meth:`DataFrameGroupBy.apply` that was returning a completely empty DataFrame when all return values of ``func`` were ``None`` instead of returning an empty DataFrame with the original columns and dtypes. (:issue:`57775`) +- Fixed bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`) +- Fixed bug in :meth:`Series.rank` that doesn't preserve missing values for nullable integers when ``na_option='keep'``. (:issue:`56976`) +- Fixed bug in :meth:`Series.replace` and :meth:`DataFrame.replace` inconsistently replacing matching instances when ``regex=True`` and missing values are present. (:issue:`56599`) Categorical ^^^^^^^^^^^ diff --git a/pandas/core/common.py b/pandas/core/common.py index 77e986a26fbe9..bf270efab8c5b 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -236,7 +236,7 @@ def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLi values = list(values) elif isinstance(values, ABCIndex): return values._values - elif isinstance(values, ABCSeries): + elif isinstance(values, ABCSeries) and values.dtype.kind != "S": return values._values if isinstance(values, list) and dtype in [np.object_, object]: diff --git a/pandas/tests/frame/methods/test_set_index.py b/pandas/tests/frame/methods/test_set_index.py index 198cab0e91eab..5dca06afe72d6 100644 --- a/pandas/tests/frame/methods/test_set_index.py +++ b/pandas/tests/frame/methods/test_set_index.py @@ -617,6 +617,17 @@ def test_set_index_raise_on_len( with pytest.raises(ValueError, match=msg): df.set_index(["A", df.A, box(values)], drop=drop, append=append) + def test_set_index_with_FLS_Dtype(self): + arr = np.array(["apple", "banana", "orange", "grape"], dtype="S6") + + # Attempt to create a DataFrame with an array with FLS Dtype + df = DataFrame(Series(arr), columns=["fruits"]) + + # Create Index that converts FLS Dtype to object + expected = Index(data=Series(arr), name="fruits") + df.set_index("fruits", inplace=True) + tm.assert_index_equal(df.index, expected) + class TestSetIndexCustomLabelType: def test_set_index_custom_label_type(self): diff --git a/pandas/tests/indexes/test_index_new.py b/pandas/tests/indexes/test_index_new.py index b544ebac43ece..073f99d938bcd 100644 --- a/pandas/tests/indexes/test_index_new.py +++ b/pandas/tests/indexes/test_index_new.py @@ -185,6 +185,18 @@ def test_constructor_datetimes_mixed_tzs(self): expected = Index([dt1, dt2], dtype=object) tm.assert_index_equal(result, expected) + def test_FLS_to_object_conversion(self): + # Create NumPy array of fixed-length strings + arr = np.array(["apple", "banana", "orange", "grape"], dtype="S6") + # Create expected array for index + expected_arr = np.array( + [b"apple", b"banana", b"orange", b"grape"], dtype=object + ) + # Create Index that converts FLS Dtype to object + index = Index(data=Series(arr), name="fruits") + expected = Index(data=Series(expected_arr), name="fruits") + tm.assert_index_equal(index, expected) + class TestDtypeEnforced: # check we don't silently ignore the dtype keyword