dahlia / wikidata

Wikidata client library for Python

Home Page:https://pypi.org/project/Wikidata/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wikidata.datavalue.DatavalueError: 9: time precision other than 11 or 14 is unsupported

az0 opened this issue · comments

This date of birth is just the year 1950 instead of the full date. How would I get the partial data 1950 without this exception?

>>> from wikidata.client import Client                                              
>>> client = Client()  # doctest: +SKIP                                             
>>> prop_dob = client.get('P569')                                                      
>>> entity = client.get('Q4794599')
>>> entity[prop_dob]

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/z/.local/lib/python3.5/site-packages/wikidata/entity.py", line 160, in __getitem__
    result = self.getlist(key)
  File "/home/z/.local/lib/python3.5/site-packages/wikidata/entity.py", line 191, in getlist
    for snak in (claim['mainsnak'] for claim in claims)]
  File "/home/z/.local/lib/python3.5/site-packages/wikidata/entity.py", line 191, in <listcomp>
    for snak in (claim['mainsnak'] for claim in claims)]
  File "/home/z/.local/lib/python3.5/site-packages/wikidata/client.py", line 178, in decode_datavalue
    return decode(self, datatype, datavalue)
  File "/home/z/.local/lib/python3.5/site-packages/wikidata/datavalue.py", line 127, in __call__
    return method(client, datavalue)
  File "/home/z/.local/lib/python3.5/site-packages/wikidata/datavalue.py", line 210, in time
    datavalue
wikidata.datavalue.DatavalueError: 9: time precision other than 11 or 14 is unsupported: {'type': 'time', 'value': {'precision': 9, 'timezone': 0, 'after': 0, 'before': 0, 'time': '+1950-01-01T00:00:00Z', 'calendarmodel': 'http://www.wikidata.org/entity/Q1985727'}}

You can always access to its underlying data through attributes property (though it's undocumented), e.g.:

entity.attributes['claims'][prop_dob.id]

OK, I see the year 1950 here, and the precison=9 means year. Thank you

entity.attributes['claims'][prop_dob.id][0]['mainsnak']['datavalue']['value']['time']

This should be closed with #26