ajfriend / pydeck-h3

0 stars 1 forks source link

numpy types don't json.dumps() #8

Open ajfriend opened 3 years ago

ajfriend commented 3 years ago

fix in pydeck?

ajfriend commented 3 years ago

The numpy.int64 issue appears with a very hard to decipher message like:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-d0f590e1c103> in <module>
      1 import pydeck_h3 as pdh
      2 
----> 3 pdh.hexcluster.plot(supercluster, opacity=.5, col_color='count').to_html()

~/work/eats_demand_response/env/lib/python3.8/site-packages/pydeck/bindings/deck.py in to_html(self, filename, open_browser, notebook_display, iframe_width, iframe_height, as_string, offline, **kwargs)
    174             Returns absolute path of the file
    175         """
--> 176         deck_json = self.to_json()
    177         f = deck_to_html(
    178             deck_json,

~/work/eats_demand_response/env/lib/python3.8/site-packages/pydeck/bindings/json_tools.py in to_json(self)
     91         Return a JSON-ified version of the Deck object.
     92         """
---> 93         return serialize(self)

~/work/eats_demand_response/env/lib/python3.8/site-packages/pydeck/bindings/json_tools.py in serialize(serializable)
     76 def serialize(serializable):
     77     """Takes a serializable object and JSONifies it"""
---> 78     return json.dumps(serializable, sort_keys=True, default=default_serialize)
     79 
     80 

~/.pyenv/versions/3.8.6/lib/python3.8/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    232     if cls is None:
    233         cls = JSONEncoder
--> 234     return cls(
    235         skipkeys=skipkeys, ensure_ascii=ensure_ascii,
    236         check_circular=check_circular, allow_nan=allow_nan, indent=indent,

~/.pyenv/versions/3.8.6/lib/python3.8/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)

~/.pyenv/versions/3.8.6/lib/python3.8/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,

~/work/eats_demand_response/env/lib/python3.8/site-packages/pydeck/bindings/json_tools.py in default_serialize(o, remap_function)
     64 def default_serialize(o, remap_function=lower_camel_case_keys):
     65     """Default method for rendering JSON from a dictionary"""
---> 66     attrs = vars(o)
     67     attrs = {k: v for k, v in attrs.items() if v is not None}
     68     for ignore_attr in IGNORE_KEYS:

TypeError: vars() argument must have __dict__ attribute
ajfriend commented 3 years ago

We either have to fix the json parsing to handle these, or make it easier for the user to understand what's happening so they can convert the type.