cds-astro / mocpy

Python library to easily create and manipulate MOCs (Multi-Order Coverage maps)
https://cds-astro.github.io/mocpy/
BSD 3-Clause "New" or "Revised" License
59 stars 33 forks source link

JSON serialization of empty space MOC fails #146

Closed ManonMarchand closed 2 months ago

ManonMarchand commented 3 months ago

To reproduce:

from mocpy import MOC
empty = MOC.new_empty(max_depth=0)
empty.serialize("json")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/manon.marchand/Documents/cds-astro-github/mocpy/python/mocpy/serializer.py", line 47, in serialize
    return json.loads(json_str)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/manon.marchand/.conda/envs/mocpy-dev/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/manon.marchand/.conda/envs/mocpy-dev/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/manon.marchand/.conda/envs/mocpy-dev/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)

(causes errors with the MOCServer that loves to return empty MOCs, see issue #143 )

fxpineau commented 3 months ago

OK, it is in the JSON serialization on the Rust side, there is a spurious ','... I am going to fix moc-lib-rust.

fxpineau commented 3 months ago

Fixed in MOC Lib Rust, see this commit, since v0.15. Already pushed on crates.io and fixed in MOCPy branch pyo3v21, see first commit.