|
10 | 10 |
|
11 | 11 | import numpy as np |
12 | 12 | import pandas as pd |
13 | | -import pandas.io.formats.style as pd_style |
| 13 | + |
| 14 | +try: |
| 15 | + import pandas.io.formats.style as pd_style |
| 16 | +except ImportError: |
| 17 | + pd_style = None |
14 | 18 |
|
15 | 19 | try: |
16 | 20 | import polars as pl |
|
40 | 44 | "warn_on_int_to_str_conversion", |
41 | 45 | } |
42 | 46 | _ORIGINAL_DATAFRAME_REPR_HTML = pd.DataFrame._repr_html_ |
43 | | -_ORIGINAL_DATAFRAME_STYLE_REPR_HTML = pd_style.Styler._repr_html_ |
| 47 | +_ORIGINAL_DATAFRAME_STYLE_REPR_HTML = ( |
| 48 | + None if pd_style is None else pd_style.Styler._repr_html_ |
| 49 | +) |
44 | 50 | _ORIGINAL_POLARS_DATAFRAME_REPR_HTML = pl.DataFrame._repr_html_ |
45 | 51 | _CONNECTED = True |
46 | 52 |
|
@@ -92,12 +98,14 @@ def init_notebook_mode( |
92 | 98 | if all_interactive: |
93 | 99 | pd.DataFrame._repr_html_ = _datatables_repr_ |
94 | 100 | pd.Series._repr_html_ = _datatables_repr_ |
95 | | - pd_style.Styler._repr_html_ = _datatables_repr_ |
| 101 | + if pd_style is not None: |
| 102 | + pd_style.Styler._repr_html_ = _datatables_repr_ |
96 | 103 | pl.DataFrame._repr_html_ = _datatables_repr_ |
97 | 104 | pl.Series._repr_html_ = _datatables_repr_ |
98 | 105 | else: |
99 | 106 | pd.DataFrame._repr_html_ = _ORIGINAL_DATAFRAME_REPR_HTML |
100 | | - pd_style.Styler._repr_html_ = _ORIGINAL_DATAFRAME_STYLE_REPR_HTML |
| 107 | + if pd_style is not None: |
| 108 | + pd_style.Styler._repr_html_ = _ORIGINAL_DATAFRAME_STYLE_REPR_HTML |
101 | 109 | pl.DataFrame._repr_html_ = _ORIGINAL_POLARS_DATAFRAME_REPR_HTML |
102 | 110 | if hasattr(pd.Series, "_repr_html_"): |
103 | 111 | del pd.Series._repr_html_ |
@@ -267,7 +275,7 @@ def to_html_datatable( |
267 | 275 | use_to_html=False, |
268 | 276 | **kwargs |
269 | 277 | ): |
270 | | - if use_to_html or isinstance(df, pd_style.Styler): |
| 278 | + if use_to_html or (pd_style is not None and isinstance(df, pd_style.Styler)): |
271 | 279 | return to_html_datatable_using_to_html( |
272 | 280 | df=df, |
273 | 281 | caption=caption, |
@@ -445,7 +453,7 @@ def to_html_datatable_using_to_html( |
445 | 453 | # default UUID in Pandas styler objects has uuid_len=5 |
446 | 454 | or str(uuid.uuid4())[:5] |
447 | 455 | ) |
448 | | - if isinstance(df, pd_style.Styler): |
| 456 | + if pd_style is not None and isinstance(df, pd_style.Styler): |
449 | 457 | if not showIndex: |
450 | 458 | try: |
451 | 459 | df = df.hide() |
|
0 commit comments