Skip to content

BUG: assert_frame_equal triggers DeprecationWarning with column with empty lists/arrays #59776

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

We are running into this in the pyarrow test suite. Reproducer on current main:

empty_list_array1 = np.empty((3,), dtype=object)
empty_list_array1.fill([])
df1 = pd.DataFrame({'a': empty_list_array1})

empty_list_array2 = np.empty((3,), dtype=object)
empty_list_array2.fill(np.array([], dtype=object))
df2 = pd.DataFrame({'a': empty_list_array2})

import warnings
warnings.simplefilter("always")

gives:

>>> pd.testing.assert_frame_equal(df1, df2)
/pandas/core/dtypes/missing.py:503: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  return lib.array_equivalent_object(left, right)

The above is with numpy 1.26 and pandas main, but also see the same with latest numpy and pandas (2.1.1 and 2.2.2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions