dahlia / wikidata

Wikidata client library for Python
https://pypi.org/project/Wikidata/
GNU General Public License v3.0
337 stars 31 forks source link

do not crash when facing unsupported calendar models #61

Open DavidDoukhan opened 2 months ago

DavidDoukhan commented 2 months ago

Dear Maintainer,

Here is a simple proposal for avoiding crashes in situations when unsupported calendar models are found in wikidata (see issue #54).

The minimalist strategy consist to return the raw dictionary of unsupported calendar models instead of having the program crashing.

See this entity with a Julian birthdate :

from wikidata.client import Client
client = Client()
birthdate = client.get('P569')
x = 'Q675908'
entity= client.get(x)
print(entity[birthdate])

{'value': {'time': '+1557-09-16T00:00:00Z', 'timezone': 0, 'before': 0, 'after': 0, 'precision': 11, 'calendarmodel': 'http://www.wikidata.org/entity/Q1985786'}, 'type': 'time'}

This fix do not affect entities with supported calendar models:

x = 'Q2897944'
entity= client.get(x)
print(entity[birthdate])

1951-12-02

I believe this small fix help users to define appropriate strategies when facing unsupported calendar models, instead of having the whole program crash, or having to implement alternative decoders. Users already need to check date types that could be int, date, datetime, or tuple. They'll may understand that when it is a dictionary, they need to do appropriate processings.

Let me know if you think this proposal is useful and consistent with the philosophy of this project

Kind regards, and thanks again for this usefull framework !

DavidDoukhan commented 1 month ago

Sorry for the late response. Everything looks okay to me. Could you add an entry for it to the changelog?

done!