jyotisham / jyotisha

Python tools for the astronomical / astrological vedAnga of Hindus
MIT License
88 stars 53 forks source link

JsonObject.read_from_file error? #33

Closed karthikraman closed 5 years ago

karthikraman commented 5 years ago

Perhaps because of some wrong version?

ERROR: 2019-04-15 07:46:26,182 {common.py:170}: Error reading /home/karthik/Documents/Chennai-2018.json :
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/sanskrit_data/schema/common.py", line 162, in read_from_file
    obj = cls.make_from_dict(jsonpickle.decode(fhandle.read()))
  File "/usr/local/lib/python3.6/dist-packages/sanskrit_data/schema/common.py", line 133, in make_from_dict
    recursively_set_jsonpickle_type(dict_without_id)
  File "/usr/local/lib/python3.6/dist-packages/sanskrit_data/schema/common.py", line 124, in recursively_set_jsonpickle_type
    some_dict[JSONPICKLE_TYPE_FIELD] = json_class_index[wire_type].__module__ + "." + wire_type
KeyError: 'Panchangam'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./update_test_json.py", line 19, in <module>
    panchangam_actual = JsonObject.read_from_file(filename=os.path.join(ORIG_DATA_PATH, fname))
  File "/usr/local/lib/python3.6/dist-packages/sanskrit_data/schema/common.py", line 171, in read_from_file
    raise e
  File "/usr/local/lib/python3.6/dist-packages/sanskrit_data/schema/common.py", line 167, in read_from_file
    obj = cls.make_from_dict_list(jsonpickle.decode(fhandle.read()))
  File "/usr/local/lib/python3.6/dist-packages/sanskrit_data/schema/common.py", line 144, in make_from_dict_list
    assert isinstance(input_dict_list, list)
AssertionError
karthikraman commented 5 years ago

I'm basically trying to read a pre-written json file and dump it with floating_point_precision=4:

TEST_DATA_PATH = os.path.join(os.path.dirname(__file__), 'spatio_temporal/data')
ORIG_DATA_PATH = os.path.expanduser('~/Documents')
for fname in sys.argv[1:]:
    panchangam_actual = JsonObject.read_from_file(filename=os.path.join(ORIG_DATA_PATH, fname))
    panchangam_actual.dump_to_file(filename=os.path.join(TEST_DATA_PATH, fname), floating_point_precision=4)
vvasuki commented 5 years ago

How did you generate this file you're reading? Can you attach it here? A generally safe way to create a file is to dump a python object.

karthikraman commented 5 years ago

The file was generated using get_panchangam Chennai-2019.json.gz

annual.py
1551:                 panchangam.dump_to_file(filename=fname)

This should have worked, right?

vvasuki commented 5 years ago

I think I got it.

The line 1525 in panchAngam should run in order for the reading to work.

common.update_json_class_index(sys.modules[__name__])

Which is why the reading happens properly in test_annual.py (which I updated and ran with your file) - it does:

from jyotisha.panchangam.spatio_temporal import City, annual

which runs the aforementioned line. .