File tree 3 files changed +25
-3
lines changed
3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 43
43
import pandas .core .algorithms as algos
44
44
import pandas .core .common as com
45
45
import pandas .core .missing as missing
46
+ from pandas .errors import UnserializableWarning
46
47
from pandas .io .formats .printing import pprint_thing
47
48
from pandas .io .formats .format import format_percentiles
48
49
from pandas .tseries .frequencies import to_offset
@@ -138,7 +139,12 @@ def _ipython_display_(self):
138
139
# Series doesn't define _repr_html_ or _repr_latex_
139
140
latex = self ._repr_latex_ () if hasattr (self , '_repr_latex_' ) else None
140
141
html = self ._repr_html_ () if hasattr (self , '_repr_html_' ) else None
141
- table_schema = self ._repr_table_schema_ ()
142
+ try :
143
+ table_schema = self ._repr_table_schema_ ()
144
+ except Exception as e :
145
+ warnings .warn ("Cannot create table schema representation. "
146
+ "{}" .format (e ), UnserializableWarning )
147
+ table_schema = None
142
148
# We need the inital newline since we aren't going through the
143
149
# usual __repr__. See
144
150
# https://github.com/pandas-dev/pandas/pull/14904#issuecomment-277829277
Original file line number Diff line number Diff line change @@ -55,3 +55,11 @@ class ParserWarning(Warning):
55
55
one specified by the user due to lack of support or functionality for
56
56
parsing particular attributes of a CSV file with the requsted engine
57
57
"""
58
+
59
+
60
+ class UnserializableWarning (Warning ):
61
+ """
62
+ Warnng that is raised when a DataFrame cannot be serialzed.
63
+
64
+ .. versionadded:: 0.20.0
65
+ """
Original file line number Diff line number Diff line change 5
5
import pandas as pd
6
6
7
7
from pandas import compat
8
+ from pandas .errors import UnserializableWarning
8
9
import pandas .io .formats .printing as printing
9
10
import pandas .io .formats .format as fmt
10
11
import pandas .util .testing as tm
@@ -177,9 +178,16 @@ def test_publishes_not_implemented(self):
177
178
178
179
make_patch = self .mock .patch ('IPython.display.display' )
179
180
opt = pd .option_context ('display.html.table_schema' , True )
180
- with opt , make_patch as mock_display : # noqa
181
- with pytest .raises ( NotImplementedError ) :
181
+ with opt , make_patch as mock_display :
182
+ with pytest .warns ( UnserializableWarning ) as record :
182
183
df ._ipython_display_ ()
184
+ args , _ = mock_display .call_args
185
+ arg , = args # just one argument
186
+
187
+ expected = {'text/plain' , 'text/html' }
188
+ assert set (arg .keys ()) == expected
189
+ assert "orient='table' is not supported for MultiIndex" in (
190
+ record [- 1 ].message .args [0 ])
183
191
184
192
def test_config_on (self ):
185
193
df = pd .DataFrame ({"A" : [1 , 2 ]})
You can’t perform that action at this time.
0 commit comments