Skip to content

json serialiser errors with numpy int64 #83439

Closed

Description

@TonyHirst
mannequin
BPO 39258
Nosy @tirkarthi
Superseder
  • bpo-24313: json fails to serialise numpy.int64
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-01-08.12:31:36.833>
    created_at = <Date 2020-01-08.11:17:19.059>
    labels = ['3.7', 'library']
    title = 'json serialiser errors with numpy int64'
    updated_at = <Date 2020-01-08.12:31:36.819>
    user = 'https://bugs.python.org/TonyHirst'

    bugs.python.org fields:

    activity = <Date 2020-01-08.12:31:36.819>
    actor = 'xtreak'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-08.12:31:36.833>
    closer = 'xtreak'
    components = ['Library (Lib)']
    creation = <Date 2020-01-08.11:17:19.059>
    creator = 'Tony Hirst'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39258
    keywords = []
    message_count = 5.0
    messages = ['359579', '359580', '359582', '359583', '359584']
    nosy_count = 2.0
    nosy_names = ['xtreak', 'Tony Hirst']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '24313'
    type = None
    url = 'https://bugs.python.org/issue39258'
    versions = ['Python 3.7']

    Activity

    1. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jan 8, 2020
    2. TonyHirst commented on Jan 8, 2020

      TonyHirstmannequin
      MannequinAuthor
      import json
      import numpy as np
      
      json.dumps( {'int64': np.int64(1)})
      
      TypeError: Object of type int64 is not JSON serializable 
      ---------------------------------------------------------------------------
      TypeError                                 Traceback (most recent call last)
      <ipython-input-67-e2b056f3a557> in <module>
      ----> 1 json.dumps( {'int64': np.int64(1)})
      
      /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
          229         cls is None and indent is None and separators is None and
          230         default is None and not sort_keys and not kw):
      --> 231         return _default_encoder.encode(obj)
          232     if cls is None:
          233         cls = JSONEncoder
      
      /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/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)
      
      /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/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,
      
      /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py in default(self, o)
          177 
          178         """
      --> 179         raise TypeError(f'Object of type {o.__class__.__name__} '
          180                         f'is not JSON serializable')
          181 
      
      TypeError: Object of type int64 is not JSON serializable
      
      ```\`
      
    3. TonyHirst commented on Jan 8, 2020

      TonyHirstmannequin
      MannequinAuthor

      Apols - this is probably strictly a numpy issue.

      See: numpy/numpy#12481

    4. TonyHirst commented on Jan 8, 2020

      TonyHirstmannequin
      MannequinAuthor

      Previously posted issue: https://bugs.python.org/issue22107

    5. TonyHirst commented on Jan 8, 2020

      TonyHirstmannequin
      MannequinAuthor

      Argh: previous was incorrect associated issue: correct issue: https://bugs.python.org/issue24313

    6. tirkarthi commented on Jan 8, 2020

      @tirkarthi
      Member

      Closing it as duplicate.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions