Skip to content

Commit 751c96d

Browse files
committed
fix: Correct DataFrame widget rendering in Colab
1 parent be1dc28 commit 751c96d

File tree

3 files changed

+151
-78
lines changed

3 files changed

+151
-78
lines changed

bigframes/dataframe.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,12 @@ def _get_anywidget_bundle(self, include=None, exclude=None):
860860

861861
# Handle both tuple (data, metadata) and dict returns
862862
if isinstance(widget_repr_result, tuple):
863-
widget_repr = dict(widget_repr_result[0]) # Extract data dict from tuple
863+
widget_repr, widget_metadata = widget_repr_result
864864
else:
865-
widget_repr = dict(widget_repr_result)
865+
widget_repr = widget_repr_result
866+
widget_metadata = None
867+
868+
widget_repr = dict(widget_repr)
866869

867870
# At this point, we have already executed the query as part of the
868871
# widget construction. Let's use the information available to render
@@ -873,6 +876,8 @@ def _get_anywidget_bundle(self, include=None, exclude=None):
873876
widget._cached_data, widget.row_count
874877
)
875878

879+
if widget_metadata is not None:
880+
return widget_repr, widget_metadata
876881
return widget_repr
877882

878883
def _create_text_representation(

notebooks/dataframes/anywidget_mode.ipynb

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@
107107
"output_type": "stream",
108108
"text": [
109109
"state gender year name number\n",
110-
" AL F 1910 Vera 71\n",
111-
" AR F 1910 Viola 37\n",
112-
" AR F 1910 Alice 57\n",
113-
" AR F 1910 Edna 95\n",
114-
" AR F 1910 Ollie 40\n",
115-
" CA F 1910 Beatrice 37\n",
116-
" CT F 1910 Marion 36\n",
117-
" CT F 1910 Marie 36\n",
118-
" FL F 1910 Alice 53\n",
119-
" GA F 1910 Thelma 133\n",
110+
" AL F 1910 Annie 482\n",
111+
" AL F 1910 Myrtle 104\n",
112+
" AR F 1910 Lillian 56\n",
113+
" CT F 1910 Anne 38\n",
114+
" CT F 1910 Frances 45\n",
115+
" FL F 1910 Margaret 53\n",
116+
" GA F 1910 Mae 73\n",
117+
" GA F 1910 Beatrice 96\n",
118+
" GA F 1910 Lola 47\n",
119+
" IA F 1910 Viola 49\n",
120120
"...\n",
121121
"\n",
122122
"[5552452 rows x 5 columns]\n"
@@ -196,12 +196,12 @@
196196
{
197197
"data": {
198198
"application/vnd.jupyter.widget-view+json": {
199-
"model_id": "2aad385a8a2f411c822dafe7b07fbad8",
199+
"model_id": "dd2c2cb542ef4045a186328da52b00d1",
200200
"version_major": 2,
201201
"version_minor": 1
202202
},
203203
"text/html": [
204-
"<table border=\"1\" class=\"dataframe table table-striped table-hover\" id=\"table-4036e4dc-c2f5-4f7a-8e53-8b31df4a8e13\">\n",
204+
"<table border=\"1\" class=\"dataframe table table-striped table-hover\" id=\"table-df8d5989-5d00-4f81-a8b3-6f25f7292fe1\">\n",
205205
" <thead>\n",
206206
" <tr style=\"text-align: left;\">\n",
207207
" <th style=\"text-align: left;\" class=\"sortable\"><div style=\"resize: horizontal; overflow: auto; box-sizing: border-box; width: 100%; height: 100%; padding: 0.5em;\">state</div></th>\n",
@@ -482,12 +482,12 @@
482482
{
483483
"data": {
484484
"application/vnd.jupyter.widget-view+json": {
485-
"model_id": "0c0b83e7e3c048ff8abb525e1bfd6c5f",
485+
"model_id": "99ef316da3b9446abcb69f53d24fd133",
486486
"version_major": 2,
487487
"version_minor": 1
488488
},
489489
"text/plain": [
490-
"TableWidget(orderable_columns=['state', 'gender', 'year', 'name', 'number'], page_size=10, row_count=5552452, …"
490+
"<bigframes.display.anywidget.TableWidget object at 0x7f30e068a5d0>"
491491
]
492492
},
493493
"execution_count": 7,
@@ -596,12 +596,12 @@
596596
{
597597
"data": {
598598
"application/vnd.jupyter.widget-view+json": {
599-
"model_id": "6a60e5dd37c64e76a8e3804dd3531f70",
599+
"model_id": "14bd45e6e88a46aca2f2e47594bf6b45",
600600
"version_major": 2,
601601
"version_minor": 1
602602
},
603603
"text/plain": [
604-
"TableWidget(orderable_columns=['state', 'gender', 'year', 'name', 'number'], page_size=10, row_count=5, table_…"
604+
"<bigframes.display.anywidget.TableWidget object at 0x7f30dc58c550>"
605605
]
606606
},
607607
"execution_count": 9,
@@ -636,7 +636,7 @@
636636
"data": {
637637
"text/html": [
638638
"✅ Completed. \n",
639-
" Query processed 85.9 kB in 14 seconds of slot time.\n",
639+
" Query processed 85.9 kB in 15 seconds of slot time.\n",
640640
" "
641641
],
642642
"text/plain": [
@@ -693,12 +693,12 @@
693693
{
694694
"data": {
695695
"application/vnd.jupyter.widget-view+json": {
696-
"model_id": "893065f8a0164648b241f2cc3d1a9271",
696+
"model_id": "d33e19fd675944b68e61b7e90b126647",
697697
"version_major": 2,
698698
"version_minor": 1
699699
},
700700
"text/html": [
701-
"<table border=\"1\" class=\"dataframe table table-striped table-hover\" id=\"table-531b95b3-561a-4b18-a203-89c867b7bddc\">\n",
701+
"<table border=\"1\" class=\"dataframe table table-striped table-hover\" id=\"table-030406a6-8ac6-4c05-9a58-fd8771d1c76a\">\n",
702702
" <thead>\n",
703703
" <tr style=\"text-align: left;\">\n",
704704
" <th style=\"text-align: left;\" ><div style=\"resize: horizontal; overflow: auto; box-sizing: border-box; width: 100%; height: 100%; padding: 0.5em;\">result</div></th>\n",
@@ -724,7 +724,7 @@
724724
" {&#x27;application_number&#x27;: None, &#x27;class_international&#x27;: None, &#x27;filing_date&#x27;: None, &#x27;publication_date&#x27;: None, &#x27;full_response&#x27;: &#x27;{}&#x27;, &#x27;status&#x27;: &#x27;INVALID_ARGUMENT: Invalid field in objectref details, only a JSON object named gcs_metadata is allowed [type.googleapis.com/util.MessageSetPayload=\\&#x27;[dremel.DremelErrorWithDetails] { argument_error { query_error { } } debug_info { error_message_template: &quot;Invalid field in objectref details, only a JSON object named $0 is allowed&quot; error_id: 3270173750 } }\\&#x27;]&#x27;}\n",
725725
" </td>\n",
726726
" <td style=\"text-align: left; padding: 0.5em;\">\n",
727-
" gs://gcs-public-data--labeled-patents/espacenet_de73.pdf\n",
727+
" gs://gcs-public-data--labeled-patents/espacenet_de2.pdf\n",
728728
" </td>\n",
729729
" <td style=\"text-align: left; padding: 0.5em;\">\n",
730730
" EU\n",
@@ -733,45 +733,45 @@
733733
" DE\n",
734734
" </td>\n",
735735
" <td style=\"text-align: left; padding: 0.5em;\">\n",
736-
" 03.10.2018\n",
736+
" 29.08.018\n",
737737
" </td>\n",
738738
" <td style=\"text-align: left; padding: 0.5em;\">\n",
739-
" H05B 6/12\n",
739+
" E04H 6/12\n",
740740
" </td>\n",
741741
" <td style=\"text-align: left; padding: 0.5em;\">\n",
742742
" <em style=\"color: gray;\">&lt;NA&gt;</em>\n",
743743
" </td>\n",
744744
" <td style=\"text-align: left; padding: 0.5em;\">\n",
745-
" 18165514.3\n",
745+
" 18157874.1\n",
746746
" </td>\n",
747747
" <td style=\"text-align: left; padding: 0.5em;\">\n",
748-
" 03.04.2018\n",
748+
" 21.02.2018\n",
749749
" </td>\n",
750750
" <td style=\"text-align: left; padding: 0.5em;\">\n",
751-
" 30.03.2017\n",
751+
" 22.02.2017\n",
752752
" </td>\n",
753753
" <td style=\"text-align: left; padding: 0.5em;\">\n",
754-
" <em style=\"color: gray;\">&lt;NA&gt;</em>\n",
754+
" Liedtke &amp; Partner Patentanw√§lte\n",
755755
" </td>\n",
756756
" <td style=\"text-align: left; padding: 0.5em;\">\n",
757-
" BSH Hausger√§te GmbH\n",
757+
" SHB Hebezeugbau GmbH\n",
758758
" </td>\n",
759759
" <td style=\"text-align: left; padding: 0.5em;\">\n",
760-
" Acero Acero, Jesus\n",
760+
" VOLGER, Alexander\n",
761761
" </td>\n",
762762
" <td style=\"text-align: left; padding: 0.5em;\">\n",
763-
" VORRICHTUNG ZUR INDUKTIVEN ENERGIE√úBERTRAGUNG\n",
763+
" STEUERUNGSSYSTEM FÜR AUTOMATISCHE PARKHÄUSER\n",
764764
" </td>\n",
765765
" <td style=\"text-align: left; padding: 0.5em;\">\n",
766-
" EP 3 383 141 A2\n",
766+
" EP 3 366 869 A1\n",
767767
" </td>\n",
768768
" </tr>\n",
769769
" <tr>\n",
770770
" <td style=\"text-align: left; padding: 0.5em;\">\n",
771771
" {&#x27;application_number&#x27;: None, &#x27;class_international&#x27;: None, &#x27;filing_date&#x27;: None, &#x27;publication_date&#x27;: None, &#x27;full_response&#x27;: &#x27;{}&#x27;, &#x27;status&#x27;: &#x27;INVALID_ARGUMENT: Invalid field in objectref details, only a JSON object named gcs_metadata is allowed [type.googleapis.com/util.MessageSetPayload=\\&#x27;[dremel.DremelErrorWithDetails] { argument_error { query_error { } } debug_info { error_message_template: &quot;Invalid field in objectref details, only a JSON object named $0 is allowed&quot; error_id: 3270173750 } }\\&#x27;]&#x27;}\n",
772772
" </td>\n",
773773
" <td style=\"text-align: left; padding: 0.5em;\">\n",
774-
" gs://gcs-public-data--labeled-patents/espacenet_de2.pdf\n",
774+
" gs://gcs-public-data--labeled-patents/espacenet_de73.pdf\n",
775775
" </td>\n",
776776
" <td style=\"text-align: left; padding: 0.5em;\">\n",
777777
" EU\n",
@@ -780,37 +780,37 @@
780780
" DE\n",
781781
" </td>\n",
782782
" <td style=\"text-align: left; padding: 0.5em;\">\n",
783-
" 29.08.018\n",
783+
" 03.10.2018\n",
784784
" </td>\n",
785785
" <td style=\"text-align: left; padding: 0.5em;\">\n",
786-
" E04H 6/12\n",
786+
" H05B 6/12\n",
787787
" </td>\n",
788788
" <td style=\"text-align: left; padding: 0.5em;\">\n",
789789
" <em style=\"color: gray;\">&lt;NA&gt;</em>\n",
790790
" </td>\n",
791791
" <td style=\"text-align: left; padding: 0.5em;\">\n",
792-
" 18157874.1\n",
792+
" 18165514.3\n",
793793
" </td>\n",
794794
" <td style=\"text-align: left; padding: 0.5em;\">\n",
795-
" 21.02.2018\n",
795+
" 03.04.2018\n",
796796
" </td>\n",
797797
" <td style=\"text-align: left; padding: 0.5em;\">\n",
798-
" 22.02.2017\n",
798+
" 30.03.2017\n",
799799
" </td>\n",
800800
" <td style=\"text-align: left; padding: 0.5em;\">\n",
801-
" Liedtke &amp; Partner Patentanw√§lte\n",
801+
" <em style=\"color: gray;\">&lt;NA&gt;</em>\n",
802802
" </td>\n",
803803
" <td style=\"text-align: left; padding: 0.5em;\">\n",
804-
" SHB Hebezeugbau GmbH\n",
804+
" BSH Hausger√§te GmbH\n",
805805
" </td>\n",
806806
" <td style=\"text-align: left; padding: 0.5em;\">\n",
807-
" VOLGER, Alexander\n",
807+
" Acero Acero, Jesus\n",
808808
" </td>\n",
809809
" <td style=\"text-align: left; padding: 0.5em;\">\n",
810-
" STEUERUNGSSYSTEM FÜR AUTOMATISCHE PARKHÄUSER\n",
810+
" VORRICHTUNG ZUR INDUKTIVEN ENERGIE√úBERTRAGUNG\n",
811811
" </td>\n",
812812
" <td style=\"text-align: left; padding: 0.5em;\">\n",
813-
" EP 3 366 869 A1\n",
813+
" EP 3 383 141 A2\n",
814814
" </td>\n",
815815
" </tr>\n",
816816
" <tr>\n",
@@ -973,29 +973,29 @@
973973
"4 gs://gcs-public-data--labeled-patents/espacene... EU DE \n",
974974
"\n",
975975
" publication_date class_international class_us application_number \\\n",
976-
"0 03.10.2018 H05B 6/12 <NA> 18165514.3 \n",
977-
"1 29.08.018 E04H 6/12 <NA> 18157874.1 \n",
976+
"0 29.08.018 E04H 6/12 <NA> 18157874.1 \n",
977+
"1 03.10.2018 H05B 6/12 <NA> 18165514.3 \n",
978978
"2 03.10.2018 H01L 21/20 <NA> 18166536.5 \n",
979979
"3 03.10.2018 G06F 11/30 <NA> 18157347.8 \n",
980980
"4 03.10.2018 A01K 31/00 <NA> 18171005.4 \n",
981981
"\n",
982982
" filing_date priority_date_eu representative_line_1_eu \\\n",
983-
"0 03.04.2018 30.03.2017 <NA> \n",
984-
"1 21.02.2018 22.02.2017 Liedtke & Partner Patentanw√§lte \n",
983+
"0 21.02.2018 22.02.2017 Liedtke & Partner Patentanw√§lte \n",
984+
"1 03.04.2018 30.03.2017 <NA> \n",
985985
"2 16.02.2016 <NA> Scheider, Sascha et al \n",
986986
"3 19.02.2018 31.03.2017 Hoffmann Eitle \n",
987987
"4 05.02.2015 05.02.2014 Stork Bamberger Patentanw√§lte \n",
988988
"\n",
989989
" applicant_line_1 inventor_line_1 \\\n",
990-
"0 BSH Hausger√§te GmbH Acero Acero, Jesus \n",
991-
"1 SHB Hebezeugbau GmbH VOLGER, Alexander \n",
990+
"0 SHB Hebezeugbau GmbH VOLGER, Alexander \n",
991+
"1 BSH Hausger√§te GmbH Acero Acero, Jesus \n",
992992
"2 EV Group E. Thallner GmbH Kurz, Florian \n",
993993
"3 FUJITSU LIMITED Kukihara, Kensuke \n",
994994
"4 Linco Food Systems A/S Thrane, Uffe \n",
995995
"\n",
996996
" title_line_1 number \n",
997-
"0 VORRICHTUNG ZUR INDUKTIVEN ENERGIE√úBERTRAGUNG EP 3 383 141 A2 \n",
998-
"1 STEUERUNGSSYSTEM FÜR AUTOMATISCHE PARKHÄUSER EP 3 366 869 A1 \n",
997+
"0 STEUERUNGSSYSTEM FÜR AUTOMATISCHE PARKHÄUSER EP 3 366 869 A1 \n",
998+
"1 VORRICHTUNG ZUR INDUKTIVEN ENERGIE√úBERTRAGUNG EP 3 383 141 A2 \n",
999999
"2 VORRICHTUNG ZUM BONDEN VON SUBSTRATEN EP 3 382 744 A1 \n",
10001000
"3 METHOD EXECUTED BY A COMPUTER, INFORMATION PRO... EP 3 382 553 A1 \n",
10011001
"4 MASTHÄHNCHENCONTAINER ALS BESTANDTEIL EINER E... EP 3 381 276 A1 \n",

0 commit comments

Comments
 (0)