mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-24 15:28:28 +01:00
TabularData: Fix drop_duplicates for rich_text NaN.
When filling missing values with `ui.rich_text` (i.e. in experiments show CMD), those values were not being correctly matched against `self._fill_value`)
This commit is contained in:
+3
-1
@@ -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)
|
||||
|
||||
@@ -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"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user