Page MenuHomePhabricator

Pywikibot crashes on items with quantities with units. Need to implement unit support in pywikibot WbQuanity
Closed, ResolvedPublic

Description

This was a task to implement unit support until I realized that Pywikibot currently crashes on items that have quantities with units on it!! You'll get:

NotImplementedError: Currently only unit-less quantities are supported
<type 'exceptions.NotImplementedError'>
CRITICAL: Closing network session.

Units just got deployed to Wikidata. Pywikibot should also implement support for units. Looks like WbQuantity is already prepared, but not completed for this:

class WbQuantity(object):

    """A Wikibase quantity representation."""

    def __init__(self, amount, unit=None, error=None):
        u"""
        Create a new WbQuantity object.

        @param amount: number representing this quantity
        @type amount: float
        @param unit: not used (only unit-less quantities are supported)
        @param error: the uncertainty of the amount (e.g. ±1)
        @type error: float, or tuple of two floats, where the first value is
                     the upper error and the second is the lower error value.

The unit should be a Wikidata item.

More info at: https://www.wikidata.org/wiki/Wikidata:Units & https://www.mediawiki.org/wiki/Wikibase/DataModel#Quantities

Event Timeline

Multichill raised the priority of this task from to High.
Multichill updated the task description. (Show Details)
Multichill added a subscriber: Multichill.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptSep 10 2015, 5:37 PM
JanZerebecki moved this task from incoming to monitoring on the Wikidata board.Sep 10 2015, 6:36 PM
Multichill renamed this task from Implement unit support in pywikibot WbQuanity to Pywikibot crashes on items with quantities with units. Need to implement unit support in pywikibot WbQuanity.Sep 10 2015, 7:23 PM
Multichill updated the task description. (Show Details)
Multichill set Security to None.

Change 237475 had a related patch set uploaded (by Ladsgroup):
[FIX] Stop crashing item loads due to support of units

https://gerrit.wikimedia.org/r/237475

Ladsgroup raised the priority of this task from High to Unbreak Now!.Sep 10 2015, 7:34 PM

Change 237475 merged by jenkins-bot:
[FIX] Stop crashing item loads due to support of units

https://gerrit.wikimedia.org/r/237475

Ladsgroup lowered the priority of this task from Unbreak Now! to Normal.Sep 10 2015, 8:48 PM
Ladsgroup removed a project: Patch-For-Review.

I stopped pywikibot from crashing by a quick patch, but we need to discuss on how we want to handle units,
we can have Entity class and subclass ItemPage and other pages (alongside with Page) OR we can have unit, calender model and globes as a general class named IRI(?) which are subclassed ItemPage.

jayvdb raised the priority of this task from Normal to High.Sep 10 2015, 9:38 PM
jayvdb added a subscriber: jayvdb.

Change 243250 had a related patch set uploaded (by John Vandenberg):
[FIX] Stop crashing item loads due to support of units

https://gerrit.wikimedia.org/r/243250

Change 243250 merged by jenkins-bot:
[FIX] Stop crashing item loads due to support of units

https://gerrit.wikimedia.org/r/243250

I've been using pywikibot to handle quantities with units for the past few weeks, it seems to work fine. I don't see what else needs to be done here?

This is resolved. I do wonder if we have a follow up task to implement better unit support or did someone already implement that?

ArthurPSmith closed this task as Resolved.Nov 25 2015, 3:22 PM
Vladis13 added a subscriber: Vladis13.EditedApr 6 2016, 5:51 PM

I get the error when try run "Example 9: Add a source" from manual "Wikidata:Creating a bot".

import pywikibot
repo = pywikibot.Site("wikidata", "wikidata").data_repository()
item = pywikibot.ItemPage(repo, u"Q4115189")
item.get()

statedin = pywikibot.Claim(repo, u'P248')
itis = pywikibot.ItemPage(repo, "Q82575")
statedin.setTarget(itis)

retrieved = pywikibot.Claim(repo, u'P813')
date = pywikibot.WbTime(year=2014, month=3, day=20)
retrieved.setTarget(date)

claim.addSources([statedin, retrieved])

Also in "Example 8: Add a qualifier" with "claim.addQualifier(qname)"

Version python 3.5.1, pwb 2.0rc3.

This error was on old version item "Wikidata:Sandbox". After did remove all claims from it the error disappeared. Thus, some a claim can do the error.

jayvdb added a comment.Apr 7 2016, 2:52 AM

Could you create a subtask for that?

jayvdb added a comment.Apr 7 2016, 3:30 PM

Ah, this fix was released in pwb 2.0rc4, so you need to upgrade to avoid this problem.