Skip to content

Commit 8ffd327

Browse files
Fix error with units
1 parent a64628d commit 8ffd327

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/WikidataTextifier.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,16 @@ def from_raw(cls, value, lazylabel):
234234
)
235235

236236
def __str__(self):
237-
return f"{self.amount} {self.unit or ''}".strip()
237+
return f"{self.amount} {str(self.unit) or ''}".strip()
238238

239239
def to_json(self):
240-
return {
241-
'amount': self.amount,
242-
'unit': self.unit,
243-
'unit_QID': self.unit_id
244-
}
240+
if self.unit_id:
241+
return {
242+
'amount': self.amount,
243+
'unit': str(self.unit),
244+
'unit_QID': self.unit_id
245+
}
246+
return self.amount
245247

246248

247249
@dataclass
@@ -338,7 +340,7 @@ def to_json(self):
338340
ID_name = "QID" if self.claim.datatype == 'wikibase-item' else "PID"
339341
value = {
340342
ID_name: value['QID'],
341-
'label': value['label']
343+
'label': str(value['label'])
342344
}
343345

344346
qualifiers = [q.to_json() for q in self.qualifiers if q]
@@ -358,7 +360,7 @@ def to_triplet(self):
358360

359361
string = str(self.value)
360362
if isinstance(self.value, WikidataEntity):
361-
string = f"{self.value.label} ({self.value.id})"
363+
string = f"{str(self.value.label)} ({self.value.id})"
362364

363365
qualifiers = [q.to_triplet() for q in self.qualifiers if q]
364366
if len(qualifiers) > 0:

0 commit comments

Comments
 (0)