Skip to content

Commit

Permalink
Implemented #84 for XBRL instance files
Browse files Browse the repository at this point in the history
  • Loading branch information
manusimidt committed Jul 11, 2022
1 parent c5dd148 commit 6e6be6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 10 additions & 5 deletions xbrl/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
This module will also access other Modules i.e TaxonomySchema.py to parse the Instance file
as well as the taxonomies and linkbases used by the instance files
"""
import re
import abc
import logging
from io import StringIO, BytesIO
from typing import List
import re
import xml.etree.ElementTree as ET
from datetime import date, datetime
from io import StringIO
from typing import List

from xbrl import TaxonomyNotFound, InstanceParseException
from xbrl.cache import HttpCache
from xbrl.taxonomy import Concept, TaxonomySchema, parse_taxonomy, parse_common_taxonomy, parse_taxonomy_url
from xbrl.helper.uri_helper import resolve_uri
from xbrl.helper.xml_parser import parse_file
from xbrl.taxonomy import Concept, TaxonomySchema, parse_taxonomy, parse_common_taxonomy, parse_taxonomy_url
from xbrl.transformations import normalize, TransformationException, TransformationNotImplemented

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -335,7 +335,12 @@ def parse_xbrl(instance_path: str, cache: HttpCache, instance_url: str or None =
tax = taxonomy.get_taxonomy(taxonomy_ns)
if tax is None: tax = _load_common_taxonomy(cache, taxonomy_ns, taxonomy)

concept: Concept = tax.concepts[tax.name_id_map[concept_name]]
try:
concept: Concept = tax.concepts[tax.name_id_map[concept_name]]
except KeyError:
logger.warning(f"Instance file uses invalid concept {concept_name}, thus fact {fact_elem.attrib['id']} "
f"won't be parsed!")
continue
context: AbstractContext = context_dir[fact_elem.attrib['contextRef'].strip()]

if 'unitRef' in fact_elem.attrib:
Expand Down
3 changes: 1 addition & 2 deletions xbrl/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ def get_taxonomy(self, url: str):
Returns the taxonomy with the given namespace (if it is the current taxonomy, or if it is imported)
If the taxonomy cannot be found, the function will return None
:param url: can either be the namespace or the schema url
:return either a TaxonomySchema obj or None
:return:
:return: either a TaxonomySchema obj or None
"""
if compare_uri(self.namespace, url) or compare_uri(self.schema_url, url):
return self
Expand Down

0 comments on commit 6e6be6d

Please sign in to comment.