File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 4343import pandas .core .algorithms as algos
4444import pandas .core .common as com
4545import pandas .core .missing as missing
46+ from pandas .errors import UnserializableWarning
4647from pandas .io .formats .printing import pprint_thing
4748from pandas .io .formats .format import format_percentiles
4849from pandas .tseries .frequencies import to_offset
@@ -138,7 +139,12 @@ def _ipython_display_(self):
138139 # Series doesn't define _repr_html_ or _repr_latex_
139140 latex = self ._repr_latex_ () if hasattr (self , '_repr_latex_' ) else None
140141 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
142148 # We need the inital newline since we aren't going through the
143149 # usual __repr__. See
144150 # 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):
5555 one specified by the user due to lack of support or functionality for
5656 parsing particular attributes of a CSV file with the requsted engine
5757 """
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 55import pandas as pd
66
77from pandas import compat
8+ from pandas .errors import UnserializableWarning
89import pandas .io .formats .printing as printing
910import pandas .io .formats .format as fmt
1011import pandas .util .testing as tm
@@ -177,9 +178,16 @@ def test_publishes_not_implemented(self):
177178
178179 make_patch = self .mock .patch ('IPython.display.display' )
179180 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 :
182183 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 ])
183191
184192 def test_config_on (self ):
185193 df = pd .DataFrame ({"A" : [1 , 2 ]})
You can’t perform that action at this time.
0 commit comments