Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ajfriend opened this issue Jan 2, 2021 · 2 comments
Open

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

ajfriend opened this issue Jan 2, 2021 · 2 comments

Comments

@ajfriend
Copy link
Owner

ajfriend commented Jan 2, 2021

fix in pydeck?

@ajfriend
Copy link
Owner Author

ajfriend commented Jan 2, 2021

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
Copy link
Owner Author

ajfriend commented Jan 2, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant