@@ -153,3 +153,32 @@ def test_page_size_change_resets_sort(mock_df):
153153
154154 # to_pandas_batches called again (reset)
155155 assert mock_df .to_pandas_batches .call_count >= 2
156+
157+
158+ def test_table_widget_single_column_dataframe ():
159+ """Test that TableWidget can be created with a single-column DataFrame."""
160+ from bigframes .display .anywidget import TableWidget
161+ import bigframes .dtypes
162+
163+ mock_df = mock .create_autospec (bigframes .dataframe .DataFrame , instance = True )
164+ mock_df .columns = ["image" ]
165+ # This is the key part: simulate single-column DataFrame's dtypes property
166+ mock_df .dtypes = bigframes .dtypes .STRING_DTYPE # Using string as a stand-in
167+
168+ mock_block = mock .Mock ()
169+ mock_block .has_index = False
170+ mock_df ._block = mock_block
171+
172+ # We mock _initial_load to avoid complex setup
173+ with mock .patch .object (TableWidget , "_initial_load" ):
174+ with bigframes .option_context (
175+ "display.repr_mode" , "anywidget" , "display.max_rows" , 10
176+ ):
177+ try :
178+ widget = TableWidget (mock_df )
179+ # Check if 'image' column is considered orderable (it is a string dtype)
180+ assert "image" in widget .orderable_columns
181+ except IndexError :
182+ pytest .fail (
183+ "Creating TableWidget with single-column DataFrame raised IndexError"
184+ )
0 commit comments