diff --git a/dvc/compare.py b/dvc/compare.py index 3fd782b22..a02f6e134 100644 --- a/dvc/compare.py +++ b/dvc/compare.py @@ -260,7 +260,9 @@ class TabularData(MutableSequence[Sequence["CellT"]]): cols_to_drop: List[str] = [] for n_col, col in enumerate(self.columns): # Cast to str because Text is not hashable error - unique_vals = {str(x) for x in col if x != self._fill_value} + unique_vals = { + str(x) for x in col if str(x) != self._fill_value + } if len(unique_vals) == 1: cols_to_drop.append(self.keys()[n_col]) self.drop(*cols_to_drop) diff --git a/tests/unit/test_tabular_data.py b/tests/unit/test_tabular_data.py index 1963e1edb..22c8372ba 100644 --- a/tests/unit/test_tabular_data.py +++ b/tests/unit/test_tabular_data.py @@ -226,24 +226,24 @@ def test_dropna(axis, how, data, expected): ( "rows", [ - ["foo", "", ""], - ["foo", "foo", ""], + ["foo", "-", "-"], + ["foo", "foo", "-"], ["foo", "bar", "foobar"], ], ), - ("cols", [[""], ["foo"], ["foo"], ["bar"]]), + ("cols", [["-"], ["foo"], ["foo"], ["bar"]]), ], ) def test_drop_duplicates(axis, expected): - td = TabularData(["col-1", "col-2", "col-3"]) + td = TabularData(["col-1", "col-2", "col-3"], fill_value="-") td.extend( [["foo"], ["foo", "foo"], ["foo", "foo"], ["foo", "bar", "foobar"]] ) assert list(td) == [ - ["foo", "", ""], - ["foo", "foo", ""], - ["foo", "foo", ""], + ["foo", "-", "-"], + ["foo", "foo", "-"], + ["foo", "foo", "-"], ["foo", "bar", "foobar"], ] @@ -252,6 +252,32 @@ def test_drop_duplicates(axis, expected): assert list(td) == expected +def test_drop_duplicates_rich_text(): + from dvc.ui import ui + + td = TabularData(["col-1", "col-2", "col-3"], fill_value="-") + + td.extend( + [ + ["foo", None, ui.rich_text("-")], + ["foo", "foo"], + ["foo", "foo"], + ["foo", "bar", "foobar"], + ] + ) + + assert list(td) == [ + ["foo", "-", ui.rich_text("-")], + ["foo", "foo", "-"], + ["foo", "foo", "-"], + ["foo", "bar", "foobar"], + ] + + td.drop_duplicates("cols") + + assert list(td) == [["-"], ["foo"], ["foo"], ["bar"]] + + def test_dropna_invalid_axis(): td = TabularData(["col-1", "col-2", "col-3"])