Skip to content

Commit

Permalink
fix test of repr html
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Jun 12, 2024
1 parent 9797be6 commit 2ff8569
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cognite/client/data_classes/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def to_pandas(self) -> pandas.DataFrame: # type: ignore[override]
pandas.DataFrame: The pandas DataFrame representing this instance.
"""
pd = local_import("pandas")
if self:
index, data = zip(*((row.key, row.columns) for row in self))
return pd.DataFrame.from_records(data, index=index)
return pd.DataFrame(columns=[], index=[])
if not self:
return pd.DataFrame(columns=[], index=[])
index, data = zip(*((row.key, row.columns) for row in self))
return pd.DataFrame.from_records(data, index=index)


class RowWriteList(RowListCore[RowWrite]):
Expand Down
4 changes: 3 additions & 1 deletion tests/tests_unit/test_data_classes/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@pytest.mark.dsl
class TestRepr:
# TODO: We should auto-create these tests for all subclasses impl. _repr_html_:
def test_repr_html(self):
for cls in [Asset, Datapoints, Sequence, FileMetadata, Row, Table, ThreeDModel]:
assert len(cls()._repr_html_()) > 0
Expand All @@ -26,5 +27,6 @@ def test_repr_html_datapoint(self):
assert len(Datapoint(timestamp=0, value=0)._repr_html_()) > 0

def test_repr_html_list(self):
for cls in [AssetList, DatapointsList, RowList, TableList]:
for cls in [AssetList, DatapointsList, TableList]:
assert len(cls([cls._RESOURCE()])._repr_html_()) > 0
assert len(RowList([RowList._RESOURCE("row", columns={})])._repr_html_()) > 0

0 comments on commit 2ff8569

Please sign in to comment.