Giter VIP home page Giter VIP logo

Comments (8)

Abonia1 avatar Abonia1 commented on June 9, 2024

I have the same issue while ioiterate through my dataframes!!!! :(

from traittypes.

vidartf avatar vidartf commented on June 9, 2024

I don't know anything specific about your cases, but in general ValueError: Can't clean for JSON means some widget trait was not correctly serialized. To be able to offer any help at all, you would need to share a minimal example we can run to reproduce the error.

from traittypes.

wlievens avatar wlievens commented on June 9, 2024

I have the same issue, and everything worked before I added an Array trait using this library ...

from traittypes.

vidartf avatar vidartf commented on June 9, 2024

If someone could please share some code to reproduce this error I might be able to help.

from traittypes.

the21st avatar the21st commented on June 9, 2024

@vidartf Here's my minimum contrived example that produces this bug:

from IPython import get_ipython
import datetime
import pandas as pd

def dataframe_formatter(df):
    return { 'application/the21st': { 'rows': [{'datetime': datetime.time(10, 0) }]} }

get_ipython().display_formatter.mimebundle_formatter.for_type(pd.DataFrame, dataframe_formatter)

Displaying any dataframe in jupyter then produces an error with stack trace:

error
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-ed84ad4d2d82> in <module>
---> 1 df

/opt/venv/lib/python3.7/site-packages/IPython/core/displayhook.py in __call__(self, result)
    264             self.fill_exec_result(result)
    265             if format_dict:
--> 266                 self.write_format_data(format_dict, md_dict)
    267                 self.log_output(format_dict)
    268             self.finish_displayhook()

/opt/venv/lib/python3.7/site-packages/ipykernel/displayhook.py in write_format_data(self, format_dict, md_dict)
     69 
     70     def write_format_data(self, format_dict, md_dict=None):
---> 71         self.msg['content']['data'] = json_clean(encode_images(format_dict))
     72         self.msg['content']['metadata'] = md_dict
     73 

/opt/venv/lib/python3.7/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

/opt/venv/lib/python3.7/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

/opt/venv/lib/python3.7/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

/opt/venv/lib/python3.7/site-packages/ipykernel/jsonutil.py in <listcomp>(.0)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

/opt/venv/lib/python3.7/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

/opt/venv/lib/python3.7/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    195 
    196     # we don't understand it, it's probably an unserializable object
--> 197     raise ValueError("Can't clean for JSON: %r" % obj)

ValueError: Can't clean for JSON: datetime.time(10, 0)

from traittypes.

vidartf avatar vidartf commented on June 9, 2024

@the21st But that code doesn't use the traittypes package at all. Could you explain a little more what code in this repo that example is relevant for?

from traittypes.

the21st avatar the21st commented on June 9, 2024

@vidartf you're right. I think it might an issue in ipykernel that's the root cause. Just wanted to illustrate how it might happen.

Edit: I opened an issue there ipython/ipykernel#546

from traittypes.

vidartf avatar vidartf commented on June 9, 2024

Well, as there isn't a standard JSON primitive for dates, you would be responsible for serializing the data/datetime/time object yourself.

from traittypes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.