Skip to content

Commit d600374

Browse files
committed
raising a NotImplementedError when the row count is none
1 parent f471291 commit d600374

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

bigframes/dataframe.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,10 @@ def __repr__(self) -> str:
794794
pandas_df, row_count, query_job = self._block.retrieve_repr_request_results(
795795
max_results
796796
)
797+
if row_count is None:
798+
raise NotImplementedError(
799+
"Cannot determine total number of rows. Please use .to_pandas() to display."
800+
)
797801

798802
self._set_internal_query_job(query_job)
799803

@@ -879,6 +883,10 @@ def _repr_html_(self) -> str:
879883
pandas_df, row_count, query_job = df._block.retrieve_repr_request_results(
880884
max_results
881885
)
886+
if row_count is None:
887+
raise NotImplementedError(
888+
"Cannot determine total number of rows. Please use .to_pandas() to display."
889+
)
882890

883891
self._set_internal_query_job(query_job)
884892
column_count = len(pandas_df.columns)

tests/system/small/test_anywidget.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
1516
import pandas as pd
1617
import pytest
1718

1819
import bigframes as bf
20+
import bigframes.pandas as bpd
1921

2022
pytest.importorskip("anywidget")
2123

@@ -530,6 +532,34 @@ def test_widget_row_count_reflects_actual_data_available(
530532
assert widget.page_size == 2 # Respects the display option
531533

532534

535+
def test_repr_html_raises_when_row_count_is_none(monkeypatch):
536+
df = bpd.DataFrame({"col1": [1, 2, 3]})
537+
538+
def mock_retrieve_repr_request_results(*args, **kwargs):
539+
return df.to_pandas(), None, None
540+
541+
monkeypatch.setattr(
542+
df._block, "retrieve_repr_request_results", mock_retrieve_repr_request_results
543+
)
544+
545+
with pytest.raises(NotImplementedError):
546+
df._repr_html_()
547+
548+
549+
def test_repr_raises_when_row_count_is_none(monkeypatch):
550+
df = bpd.DataFrame({"col1": [1, 2, 3]})
551+
552+
def mock_retrieve_repr_request_results(*args, **kwargs):
553+
return df.to_pandas(), None, None
554+
555+
monkeypatch.setattr(
556+
df._block, "retrieve_repr_request_results", mock_retrieve_repr_request_results
557+
)
558+
559+
with pytest.raises(NotImplementedError):
560+
df.__repr__()
561+
562+
533563
# TODO(shuowei): Add tests for custom index and multiindex
534564
# This may not be necessary for the SQL Cell use case but should be
535565
# considered for completeness.

0 commit comments

Comments
 (0)