manusimidt / py-xbrl

Python-based parser for parsing XBRL and iXBRL files
https://py-xbrl.readthedocs.io/en/latest/
GNU General Public License v3.0
111 stars 40 forks source link

Equals method for all fact classes #110

Open manusimidt opened 1 year ago

manusimidt commented 1 year ago

Add an eq() method to all fact classes to test for equality

stkerr commented 1 year ago

If it helps, I've been using the code below to check for fact equality:

def fact_compare(first:AbstractFact, second:AbstractFact):
    if type(first) != type(second):
        return False

    if first.value != second.value:
        return False

    if first.xml_id != second.xml_id:
        return False

    if first.footnote != second.footnote:
        return False

    if isinstance(first, NumericFact):
        first:NumericFact = first
        second:NumericFact = second

        if first.decimals != second.decimals:
            return False

        if first.unit != second.unit:
            return False

    else:
        first:TextFact = first
        second:TextFact = second

    if not context_compare(first.context, second.context):
        return False

    if not concept_compare(first.concept, second.concept):
        return False

    return True