Skip to content

Problem with NumPy arrays and JSON #248

@meteorologist15

Description

@meteorologist15

Using esgpublish v5.2.4, on an attempted publishing action, I received the following traceback:

Traceback (most recent call last):
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/esgcet/generic_netcdf.py", line 75, in mk_dataset
    out_json_data = mkd.get_records(map_json_data, scan_arg, self.json_file, user_project=self.proj_config)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/esgcet/mk_dataset.py", line 419, in get_records
    self.publog.debug("Record:\n" + json.dumps(self.dataset, indent=4))
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable

I personally used this Pandas solution to get around the issue, but perhaps other strategies may be utilized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions