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

Problem with NumPy arrays and JSON #248

Open
meteorologist15 opened this issue Jan 7, 2025 · 1 comment
Open

Problem with NumPy arrays and JSON #248

meteorologist15 opened this issue Jan 7, 2025 · 1 comment

Comments

@meteorologist15
Copy link

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.

@sashakames
Copy link
Contributor

Hi @meteorologist15 thanks for catching this (do I know you from a different context, I see you are at GFDL?) Are you running with verbose: true or --verbose, I don't think we log the error otherwise. We may need to replicate your data to LLNL so I can reproduce the issue in order to test a bugfix.

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

2 participants