beakerx
beakerx copied to clipboard
Error: Circular Reference Detected on Table Display
So this may appear to be similar to #7935 is is actually different. I was running a Dataframe into a BeakerX table and saw that I had some int64 columns and assumed they were the issue. They were not.
However, I had two columns that were of type bool in df.dtypes. When I converted these two to type object, then the dataframe was displayed correctly. Thus what ever caused an issue with int64 probably needs to be looked at for type bool as well.
This is on Pandas version 0.24.2 and BeakerX 1.4.0
Example Code:
import pandas as pd
from beakerx import *
from beakerx.object import beakerx
#Display mode: TableDisplay Widget
beakerx.pandas_display_table()
df = pd.DataFrame(data=np.zeros((5,5)), index=pd.Int64Index([0, 1, 2, 3, 4], dtype='int64'))
df # Displays properly
df.dtypes
0 float64 1 float64 2 float64 3 float64 4 float64 dtype: object
df[2] = df[2].astype(bool)
df.dtypes
0 float64 1 float64 2 bool 3 float64 4 float64 dtype: object
df # Errors out
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
916 method = get_real_method(obj, self.print_method)
917 if method is not None:
--> 918 method()
919 return True
920
/opt/conda/lib/python3.7/site-packages/beakerx/runtime.py in f()
467 def __get__(self, model_instance, model_class):
468 def f():
--> 469 display_html(TableDisplay(model_instance))
470
471 return f
/opt/conda/lib/python3.7/site-packages/beakerx/tabledisplay/tabledisplay.py in __init__(self, *args, **kwargs)
211 super(TableDisplay, self).__init__(**kwargs)
212 self.chart = Table(*args, **kwargs)
--> 213 self.model = self.chart.transform()
214 self.on_msg(self.handle_msg)
215 self.details = None
/opt/conda/lib/python3.7/site-packages/beakerx/utils.py in transform(self)
53
54 def transform(self):
---> 55 model = json.dumps(self, cls=ObjectEncoder)
56 return json.loads(model)
57
/opt/conda/lib/python3.7/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
237 separators=separators, default=default, sort_keys=sort_keys,
--> 238 **kw).encode(obj)
239
240
/opt/conda/lib/python3.7/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
/opt/conda/lib/python3.7/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
ValueError: Circular reference detected
I just ran into the same problem with Pandas 0.24.2 and BeakerX 1.4.1
Had the same bug with all of float16, float32, int8, int16, int32, ... for TableDisplay(pd.DataFrame(np.array([[1]], dtype="float32")))
Confirming I get the same bug using the same versions of pandas and beakerx as the original poster.
Hi all,
I recently saw this issue, I have been able to fix it for me using the following changes:
In beakerx_base\util.py, Line 188, replace the function with the following code:
class ObjectEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return date_time_2_millis(obj)
elif isinstance(obj, Enum):
return obj.value
elif isinstance(obj, Color):
return obj.hex()
elif isinstance(obj, pd.Series):
return obj.tolist()
elif isinstance(obj, np.ndarray):
return obj.tolist()
elif isinstance(obj, np.generic):
return obj.item()
elif hasattr(obj, "__dict__"):
d = dict(
(key, value)
for key, value in inspect.getmembers(obj)
if value is not None
and not key == "Position"
and not key == "colorProvider"
and not key == "toolTipBuilder"
and not key == "parent"
and not key.startswith("__")
and not inspect.isabstract(value)
and not inspect.isbuiltin(value)
and not inspect.isfunction(value)
and not inspect.isgenerator(value)
and not inspect.isgeneratorfunction(value)
and not inspect.ismethod(value)
and not inspect.ismethoddescriptor(value)
and not inspect.isroutine(value)
)
return d
return json.JSONEncoder.default(self,obj)