diff --git a/cognite/client/data_classes/raw.py b/cognite/client/data_classes/raw.py index 34e12bdb6b..ad6ab3c3ab 100644 --- a/cognite/client/data_classes/raw.py +++ b/cognite/client/data_classes/raw.py @@ -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]): diff --git a/tests/tests_unit/test_data_classes/test_repr.py b/tests/tests_unit/test_data_classes/test_repr.py index 9f0c04dc18..d3fc7c4719 100644 --- a/tests/tests_unit/test_data_classes/test_repr.py +++ b/tests/tests_unit/test_data_classes/test_repr.py @@ -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 @@ -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