Ejemplo n.º 1
0
def test_open_file_handle():
    xbrl_parser = XBRLParser()
    file_to_parse = "tests/sam-20130629.xml"
    try:
        xbrl_parser.parse(file(file_to_parse))
    except NameError:
        pass
Ejemplo n.º 2
0
def test_parse_Custom10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    custom_obj = xbrl_parser.parseCustom(xbrl)

    if six.PY3:

        result = len(custom_obj())

        assert result == 13

    if six.PY2 and not __pypy__:

        result = custom_obj()

        assert result[0] == ('conversionofclassbcommonstocktoclassacommonstockshares', '100000')
        assert result[1] == ('percentageofproductionvolumes', '0.90')
        assert result[2] == ('sharebasedcompensationarrangementbysharebasedpaymentawardoptionstovestineachtranche', '5000')
        assert result[3] == ('weightedaveragenumberofsharesoutstandingbasicincludingnonvestedparticipatingsecurities', '12866000')
        assert result[4] == ('incrementalcommonsharesattributabletoconversionofcommonstock', '4007000')
        assert result[5] == ('sharebasedcompensationarrangementbysharebasedpaymentawardinvestmentsharesweightedaveragegrantdat', '59.62')
        assert result[6] == ('incomeallocatedtoequityinstrumentsotherthanoptionnonvested', '7000')
        assert result[7] == ('netproceedsfromsaleofinvestmentshares', '531000')
        assert result[8] == ('weightedaveragenumberofbasicsharesoutstandingequityinstrumentsotherthanoptionnonvested', '94000')
        assert result[9] == ('sharebasedcompensationarrangementbysharebasedpaymentawardemployeeinvestmentsharespurchase', '12894')
        assert result[10] == ('provisionforreductionofdoubtfulaccounts', '-28000')
        assert result[11] == ('receiptofgovernmentgrantsforfacilitiesexpansion', '770000')
        assert result[12] == ('netincomelossallocatedtoequityinstrumentsotherthanoptionnonvested', '-143000')
Ejemplo n.º 3
0
def test_parse_GAAP10Q_Ez_XBRL():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/ggho-20140930.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                     str(file_to_parse
                                         .split("-")[1].split(".")[0][:4] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][4:6] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][6:8]),
                                     "10-Q", "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 34273.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 127.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == -1078.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == -7593.0
    assert result.data['liabilities_and_equity'] == 79451.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 13026.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 30543.0
    assert result.data['net_income_loss'] == -8642.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 0.0
    assert result.data['equity_attributable_interest'] == 309.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 0.0
    assert result.data['income_before_equity_investments'] == -8531.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 1078.0
    assert result.data['gross_profit'] == 5433.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 0.0
    assert result.data['interest_and_debt_expense'] == 0.0
Ejemplo n.º 4
0
def test_open_file_handle():
    xbrl_parser = XBRLParser()
    file_to_parse = "tests/sam-20130629.xml"
    try:
        xbrl_parser.parse(file(file_to_parse))
    except NameError:
        pass
Ejemplo n.º 5
0
 def get_page(self, url):
     page = requests.get(url)
     xbrl_parser = XBRLParser()
     # print(dir(xbrl_parser))
     b = io.StringIO(page.text)
     obj = xbrl_parser.parse(b)
     # print(obj)
     return obj
Ejemplo n.º 6
0
def test_parse_Custom10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    custom_obj = xbrl_parser.parseCustom(xbrl)

    result = len(custom_obj())
    assert result == 13
Ejemplo n.º 7
0
def test_parse_DEI10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    dei_obj = xbrl_parser.parseDEI(xbrl)

    serializer = DEISerializer()
    result = serializer.dump(dei_obj)

    assert result.data['trading_symbol'] == "SAM"
    assert result.data['company_name'] == "BOSTON BEER CO INC"
    assert result.data['shares_outstanding'] == 4007355.0
    assert result.data['public_float'] == 0.0
Ejemplo n.º 8
0
def test_parse_DEI10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    dei_obj = xbrl_parser.parseDEI(xbrl)

    serializer = DEISerializer()
    result = serializer.dump(dei_obj)

    assert result.data['trading_symbol'] == "SAM"
    assert result.data['company_name'] == "BOSTON BEER CO INC"
    assert result.data['shares_outstanding'] == 4007355.0
    assert result.data['public_float'] == 0.0
Ejemplo n.º 9
0
def test_parse_Custom10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    custom_obj = xbrl_parser.parseCustom(xbrl)

    if six.PY3:

        result = len(custom_obj())

        assert result == 13

    if six.PY2 and not __pypy__:

        result = custom_obj()

        assert result[0] == (
            'conversionofclassbcommonstocktoclassacommonstockshares', '100000')
        assert result[1] == ('percentageofproductionvolumes', '0.90')
        assert result[2] == (
            'sharebasedcompensationarrangementbysharebasedpaymentawardoptionstovestineachtranche',
            '5000')
        assert result[3] == (
            'weightedaveragenumberofsharesoutstandingbasicincludingnonvestedparticipatingsecurities',
            '12866000')
        assert result[4] == (
            'incrementalcommonsharesattributabletoconversionofcommonstock',
            '4007000')
        assert result[5] == (
            'sharebasedcompensationarrangementbysharebasedpaymentawardinvestmentsharesweightedaveragegrantdat',
            '59.62')
        assert result[6] == (
            'incomeallocatedtoequityinstrumentsotherthanoptionnonvested',
            '7000')
        assert result[7] == ('netproceedsfromsaleofinvestmentshares', '531000')
        assert result[8] == (
            'weightedaveragenumberofbasicsharesoutstandingequityinstrumentsotherthanoptionnonvested',
            '94000')
        assert result[9] == (
            'sharebasedcompensationarrangementbysharebasedpaymentawardemployeeinvestmentsharespurchase',
            '12894')
        assert result[10] == ('provisionforreductionofdoubtfulaccounts',
                              '-28000')
        assert result[11] == (
            'receiptofgovernmentgrantsforfacilitiesexpansion', '770000')
        assert result[12] == (
            'netincomelossallocatedtoequityinstrumentsotherthanoptionnonvested',
            '-143000')
Ejemplo n.º 10
0
 def get_facts_info(self):
     """
     return(element_id, amount, context_ref, unit_ref, decimals)
     """
     # parse xbrl file
     xbrl = XBRLParser.parse(file(self.xbrl_filename)) # beautiful soup type object
     facts_dict = defaultdict(list)
     
     #print xbrl
     name_space = 'jp*'
     for node in xbrl.find_all(name=re.compile(name_space+':*')):
         if 'xsi:nil' in node.attrs:
             if node.attrs['xsi:nil']=='true':
                 continue
         
         facts_dict['element_id'].append( node.name.replace(':','_') )
         facts_dict['amount'].append( node.string )
         
         facts_dict['context_ref'].append(
                     self.get_attrib_value(node, 'contextref') )
         facts_dict['unit_ref'].append( 
                     self.get_attrib_value(node, 'unitref') )
         facts_dict['decimals'].append(
                     self.get_attrib_value(node, 'decimals') )
     return pd.DataFrame( facts_dict )
Ejemplo n.º 11
0
    def parse_xbrl(self):
        # parse xbrl file
        with open(self.xbrl_filepath, 'r', encoding='utf-8') as of:
            xbrl = XBRLParser.parse(of)  # beautiful soup type object
        result_dicts = defaultdict(list)
        _idx = 0

        #print xbrl
        name_space = 'jp*'
        for node in xbrl.find_all(name=re.compile(name_space + ':*')):
            if self.ignore_pattern(node):
                continue

            row_dict = defaultdict(list)
            #default tag
            row_dict['file_nm'] = self.xbrl_filepath.rsplit('\\' or '/', 1)[1]
            row_dict['element_id'] = node.name
            row_dict['amount'] = node.string

            #cutom tag
            for tag in custom_tag:
                row_dict[tag] = self.get_attrib_value(node, tag)

            result_dicts[_idx] = row_dict
            _idx += 1
        return result_dicts
Ejemplo n.º 12
0
 def parse_file(cls, xbrl_file_path):
     data_container = EdinetXbrlObject()
     with codecs.open(xbrl_file_path, 'r', 'utf-8') as of:
         parser = XBRLParser.parse(of)
         for node in parser.find_all():
             cls.put_node(data_container, node)
     return data_container
Ejemplo n.º 13
0
    def parse_xbrl(self):
        # parse xbrl file
        with open(self.xbrl_filepath,'r',encoding='utf-8') as of:
            xbrl = XBRLParser.parse(of) # beautiful soup type object
        result_dicts = defaultdict(list)
        _idx = 0

        #print xbrl
        name_space = 'jp*'
        for node in xbrl.find_all(name=re.compile(name_space+':*')):
            if self.ignore_pattern(node):
                continue

            row_dict = defaultdict(list)
            #default tag
            row_dict['file_nm'] = self.xbrl_filepath.rsplit('\\' or '/', 1)[1]
            row_dict['element_id'] = node.name
            row_dict['amount'] = node.string

            #cutom tag
            for tag in custom_tag:
                row_dict[tag] = self.get_attrib_value(node,tag)

            result_dicts[_idx] = row_dict
            _idx += 1
        return result_dicts
Ejemplo n.º 14
0
    def get_facts_info(self):
        """
        return(element_id, amount, context_ref, unit_ref, decimals)
        """
        # parse xbrl file
        xbrl = XBRLParser.parse(open(
            self.xbrl_filename))  # beautiful soup type object
        facts_dict = defaultdict(list)

        #print xbrl
        name_space = 'jp*'
        for node in xbrl.find_all(name=re.compile(name_space + ':*')):
            if 'xsi:nil' in node.attrs:
                if node.attrs['xsi:nil'] == 'true':
                    continue

            facts_dict['element_id'].append(node.name.replace(':', '_'))
            facts_dict['amount'].append(node.string)

            facts_dict['context_ref'].append(
                self.get_attrib_value(node, 'contextref'))
            facts_dict['unit_ref'].append(
                self.get_attrib_value(node, 'unitref'))
            facts_dict['decimals'].append(
                self.get_attrib_value(node, 'decimals'))
        return pd.DataFrame(facts_dict)
Ejemplo n.º 15
0
    def parse_xbrl(self):
        with open(self.xbrl_file, 'r', encoding=settings.encode_type) as of:
            xbrl = XBRLParser.parse(of)

        result_dicts = {}
        _idx = 0
        name_space = 'jp*'

        for node in xbrl.find_all(name=re.compile(name_space + ':*')):
            if self.ignore_pattern(node):
                continue

            row_dict = {}
            row_dict['file_name'] = self.xbrl_file.rsplit(os.sep, 1)[1]
            row_dict['element_id'] = node.name
            row_dict['amount'] = node.string

            for tag in custom_tag:
                row_dict[tag] = self.get_attrib_value(node, tag)

            result_dicts[_idx] = row_dict
            _idx += 1

        return result_dicts
Ejemplo n.º 16
0
import tensorflow as tf
import os
from xbrl import XBRLParser, GAAP, GAAPSerializer
num_steps = 500
batch_size = 128

data_x = []
data_y = []

test_x = []
test_y = []
for subdir, dirs, files in os.walk("data/"):
    print(os.path.split(subdir)[-1])
    for f in files:
        xbrl_parser = XBRLParser()
        print(subdir + "/" + f)
        try:
            xbrl = xbrl_parser.parse(subdir + "/" + f)
        except:
            continue
        gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                         context="current",
                                         ignore_errors=0)
        print("We here 2")
        serializer = GAAPSerializer()
        result = serializer.dump(gaap_obj)
        if "-13-" in f:
            test_x.append([])
            for i, k in result.data:
                test_x[-1].append(k)
        else:
Ejemplo n.º 17
0
def test_parse_GAAP10K_ThomsonReuters():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/aaoi-20131231.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(
        xbrl,
        str(
            file_to_parse.split("-")[1].split(".")[0][:4] +
            file_to_parse.split("-")[1].split(".")[0][4:6] +
            file_to_parse.split("-")[1].split(".")[0][6:8]), "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 39057.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 0.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 177.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == -297.0
    assert result.data['liabilities_and_equity'] == 111057.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 6973.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 63077.0
    assert result.data['net_income_loss'] == -520.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 0.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 0.0
    assert result.data['income_before_equity_investments'] == 0.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 111057.0
    assert result.data['gross_profit'] == 6676.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 77936.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 0.0
    assert result.data['common_shares_authorized'] == 0.0
Ejemplo n.º 18
0
#! /usr/bin/env python
# encoding: utf-8

from xbrl import XBRLParser, GAAP, GAAPSerializer

xbrl_parser = XBRLParser(precision=0)

# Parse an incoming XBRL file
xbrl = xbrl_parser.parse(file("../tests/sam-20130629.xml"))

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20130629",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)

# Print out the serialized GAAP data
print result

# Parse just the DEI data from the xbrl object
dei_obj = xbrl_parser.parseDEI(xbrl)

# Serialize the DEI data
serializer = DEISerializer()
result = serializer.dump(dei_obj)

# Print out the serialized DEI data
Ejemplo n.º 19
0
#! /usr/bin/env python
# encoding: utf-8

from __future__ import print_function

from xbrl import XBRLParser, GAAP, GAAPSerializer, DEISerializer

xbrl_parser = XBRLParser(precision=0)

# Parse an incoming XBRL file
xbrl = xbrl_parser.parse("../tests/sam-20130629.xml")

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20130629",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)

# Print out the serialized GAAP data
print(result)

# Parse just the DEI data from the xbrl object
dei_obj = xbrl_parser.parseDEI(xbrl)

# Serialize the DEI data
serializer = DEISerializer()
result = serializer.dump(dei_obj)
Ejemplo n.º 20
0
def test_parse_GAAP10K_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20131228.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                     str(file_to_parse
                                         .split("-")[1].split(".")[0][:4] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][4:6] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][6:8]),
                                     "10-K", "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 104377.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 0.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 9556.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 29120.0
    assert result.data['liabilities_and_equity'] == 69900.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 0.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 302085.0
    assert result.data['net_income_loss'] == 18079.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 0.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 0.0
    assert result.data['income_before_equity_investments'] == 0.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 1050.0
    assert result.data['gross_profit'] == 104628.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 0.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
Ejemplo n.º 21
0
def test_parse_empty_file():
    xbrl_parser = XBRLParser()
    file_to_parse = "tests/nothing.xml"
    with pytest.raises(XBRLParserException):
        xbrl_parser.parse(file_to_parse)
Ejemplo n.º 22
0
def test_parse_empty_file():
    xbrl_parser = XBRLParser()
    file_to_parse = "tests/nothing.xml"
    with pytest.raises(XBRLParserException):
        xbrl_parser.parse(file_to_parse)
Ejemplo n.º 23
0
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 12:51:22 2015

This file was built to test python-xbrl package. 



@author: ptorre
"""
from xbrl import XBRLParser, GAAP, GAAPSerializer

xbrl_parser = XBRLParser()
xbrl = xbrl_parser.parse(file("rht-20150228.xml"))
#%%
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_type="10-Q",
                                 context="current",
                                 ignore_errors=0)
serialized = GAAPSerializer(gaap_obj)
print serialized.data
Ejemplo n.º 24
0
#! /usr/bin/env python
# encoding: utf-8

from __future__ import print_function

from xbrl import XBRLParser, GAAP, GAAPSerializer

xbrl_parser = XBRLParser(0)

# Parse an incoming XBRL file
xbrl = xbrl_parser.parse(file("tests/sam-20131228.xml"))

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20131228",
                                 doc_type="10-K",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)

# Print out the serialized GAAP data
print(result.data)
Ejemplo n.º 25
0
#! /usr/bin/env python
# encoding: utf-8

from __future__ import print_function

from xbrl import XBRLParser, GAAP, GAAPSerializer, DEISerializer

xbrl_parser = XBRLParser(0)

# Parse an incoming XBRL file
file_to_parse = "../tests/sam-20130629.xml"

xbrl = xbrl_parser.parse(file_to_parse)

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20131228",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)

# Print out the serialized GAAP data
print(result.data)


# Parse just the DEI data from the xbrl object
dei_obj = xbrl_parser.parseDEI(xbrl)
Ejemplo n.º 26
0
from xbrl import XBRLParser, GAAP, GAAPSerializer
import requests


def download_file():
    global dump
    url = "http://randomsite.com/file.gz"
    file = requests.get(url, stream=True)
    dump = file.raw


xbrl_parser = XBRLParser()
xbrl = xbrl_parser.parse(file("sam-20131228.xml"))
Ejemplo n.º 27
0
#! /usr/bin/env python
# encoding: utf-8
import os
import re
import pandas as pd
from xbrl import XBRLParser, GAAP, GAAPSerializer, DEISerializer

Extracted_fields=['liabilities', 'temporary_equity', 'other_comprehensive_income', 'assets', 'common_shares_issued', 'other_operating_income', 'commitments_and_contingencies', 'income_loss', 'current_assets', 'operating_expenses', 'interest_and_debt_expense', 'common_shares_authorized', 'comprehensive_income_parent', 'net_income_loss', 'common_shares_outstanding', 'net_income_loss_noncontrolling', 'net_cash_flows_investing_discontinued', 'net_cash_flows_discontinued', 'nonoperating_income_loss', 'net_cash_flows_financing_continuing', 'equity_attributable_parent', 'noncurrent_liabilities', 'income_tax_expense_benefit', 'revenue', 'net_cash_flows_investing_continuing', 'cost_of_revenue', 'comprehensive_income', 'net_cash_flows_operating_discontinued', 'stockholders_equity', 'income_from_equity_investments', 'comprehensive_income_interest', 'net_income_shareholders', 'redeemable_noncontrolling_interest', 'net_cash_flows_financing', 'equity_attributable_interest', 'extraordary_items_gain_loss', 'preferred_stock_dividends', 'income_before_equity_investments', 'net_cash_flows_operating', 'equity', 'non_current_assets', 'net_income_parent', 'net_cash_flows_operating_continuing', 'gross_profit', 'costs_and_expenses', 'liabilities_and_equity', 'operating_income_loss', 'net_cash_flows_investing', 'current_liabilities']

xbrl_parser = XBRLParser(precision=0)
# Serialize the GAAP data
serializer = GAAPSerializer()
df = pd.DataFrame(columns=Extracted_fields)
df.index.names = ['Company-date']
xml_path="~/apps/repo/python-xbrl/tests"
for root, dirs, files in os.walk("."):
    path = root.split(os.sep)
    print((len(path) -1) * '---', os.path.basename(root))
    for file in files:
        print (file)
        if re.match(r"[a-z]{3,5}\-[0-9]{8}\.xml",file):
        #if re.match(r"aaww-20131231.xml",file):
            # Parse an incoming XBRL file
            xbrl = xbrl_parser.parse(file)
            print("Process {}".format(os.path.join(root,file)))
            date_of_doc = re.search(r"[0-9]{8}",file).group()
            # Parse just the GAAP data from the xbrl object
            gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 	     doc_date=date_of_doc,
                                 	     context="current",
                                 	     ignore_errors=0)
Ejemplo n.º 28
0
def test_parse_GAAP10Q_QXInteractive():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/aaoi-20140630.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                     str(file_to_parse
                                         .split("-")[1].split(".")[0][:4] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][4:6] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][6:8]),
                                     "10-Q", "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 5606.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 85.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 978.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 1730.0
    assert result.data['liabilities_and_equity'] == 153524.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 9458.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 111781.0
    assert result.data['net_income_loss'] == 1919.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 2058.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 2058.0
    assert result.data['income_before_equity_investments'] == 0.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 106114.0
    assert result.data['gross_profit'] == 11188.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 46431.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
Ejemplo n.º 29
0
    def data_processing(self,
                        elements,
                        xbrl,
                        ignore_errors,
                        logger,
                        context_ids=[],
                        **kwargs):
        """
        Process a XBRL tag object and extract the correct value as
        stated by the context.
        """
        options = kwargs.get('options', {
            'type': 'Number',
            'no_context': False
        })

        if options['type'] == 'String':
            if len(elements) > 0:
                return elements[0].text

        if options['no_context'] == True:
            if len(elements) > 0 and XBRLParser().is_number(elements[0].text):
                return elements[0].text

        try:

            # Extract the correct values by context
            correct_elements = []
            for element in elements:
                contextrefs = element.attrs['contextref'].split('_')

                if any(
                    [context_id in contextrefs for context_id in context_ids]):
                    correct_elements.append(element)

            elements = correct_elements

            if len(elements) > 0 and XBRLParser().is_number(elements[0].text):
                return float(elements[0].text)
            else:
                return 0

            # if len(elements) > 0 and XBRLParser().is_number(elements[0].text):
            #     decimals = elements[0].attrs['decimals']
            #     if decimals is not None:
            #         attr_precision = decimals
            #         if xbrl.precision != 0 and xbrl.precison != attr_precision:
            #             xbrl.precision = attr_precision
            #     if elements:
            #         return XBRLParser().trim_decimals(elements[0].text, int(xbrl.precision))
            #     else:
            #         return 0
            # else:
            #     return 0
        except Exception as e:
            if ignore_errors == 0:
                raise XBRLParserException('value extraction error')
            elif ignore_errors == 1:
                return 0
            elif ignore_errors == 2:
                logger.error(str(e) + " error at " + ''.join(elements[0].text))
Ejemplo n.º 30
0
def test_parse_GAAP10Q_Ez_XBRL():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/ggho-20140930.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(
        xbrl,
        str(
            file_to_parse.split("-")[1].split(".")[0][:4] +
            file_to_parse.split("-")[1].split(".")[0][4:6] +
            file_to_parse.split("-")[1].split(".")[0][6:8]), "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 34273.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 127.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 58615.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == -7593.0
    assert result.data['liabilities_and_equity'] == 79451.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 13026.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 30543.0
    assert result.data['net_income_loss'] == -8642.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 0.0
    assert result.data['equity_attributable_interest'] == 309.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 0.0
    assert result.data['income_before_equity_investments'] == -8531.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 79451.0
    assert result.data['gross_profit'] == 5433.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 20836.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 0.0
    assert result.data['common_shares_authorized'] == 0.0
Ejemplo n.º 31
0
def test_parse_GAAP10Q_QXInteractive():

    xbrl_parser = XBRLParser()
    file_to_parse = "tests/aaoi-20140630.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(
        xbrl,
        str(
            file_to_parse.split("-")[1].split(".")[0][:4] +
            file_to_parse.split("-")[1].split(".")[0][4:6] +
            file_to_parse.split("-")[1].split(".")[0][6:8]), "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 5606.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 85.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 978.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 1730.0
    assert result.data['liabilities_and_equity'] == 153524.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 9458.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 111781.0
    assert result.data['net_income_loss'] == 1919.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 2058.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 2058.0
    assert result.data['income_before_equity_investments'] == 0.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 153524.0
    assert result.data['gross_profit'] == 11188.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 106114.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 14798000.0
    assert result.data['common_shares_issued'] == 14798000.0
    assert result.data['common_shares_authorized'] == 45000000.0
Ejemplo n.º 32
0
from xbrl import XBRLParser, GAAP, GAAPSerializer

xbrl_parser = XBRLParser()

xbrl = xbrl_parser.parse(
    open(
        "/Users/f1v-13/Downloads/0001558370-20-001080-xbrl/adc-20191231x10k4f0b3a.htm"
    ))

gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20131228",
                                 context="current",
                                 ignore_errors=0)

serializer = GAAPSerializer()

result = serializer.dump(gaap_obj)

print(result.data)
Ejemplo n.º 33
0
def test_parse_GAAP10Q_Rivet():

    xbrl_parser = XBRLParser()
    file_to_parse = "tests/c289-20140503.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(
        xbrl,
        str(
            file_to_parse.split("-")[1].split(".")[0][:4] +
            file_to_parse.split("-")[1].split(".")[0][4:6] +
            file_to_parse.split("-")[1].split(".")[0][6:8]), "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 12535.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 14.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 708.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == -983.0
    assert result.data['liabilities_and_equity'] == 13261.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 3497.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 726.0
    assert result.data['net_income_loss'] == -983.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == -977.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == -977.0
    assert result.data['income_before_equity_investments'] == -969.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 13261.0
    assert result.data['gross_profit'] == 2687.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 10747.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 146033000.0
    assert result.data['common_shares_authorized'] == 650000000.0
Ejemplo n.º 34
0
#! /usr/bin/env python
# encoding: utf-8
import pandas as pd
from xbrl import XBRLParser, GAAP, GAAPSerializer, DEISerializer

xbrl_parser = XBRLParser(precision=0)

# Parse an incoming XBRL file
xbrl = xbrl_parser.parse(open("../tests/aaww-20131231.xml"))

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20131231",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)

attribute = [x.encode('ascii') for x in result[0].keys()]
values = result[0].values()
df = pd.DataFrame(columns=attribute, index=['aaww'])
df.loc['aaww'] = values
print(df)

## Parse just the DEI data from the xbrl object
#dei_obj = xbrl_parser.parseDEI(xbrl)
#
## Serialize the DEI data
#serializer = DEISerializer()
Ejemplo n.º 35
0
def test_parse_GAAP10K_Fujitsu():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/aaww-20131231.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                     str(file_to_parse
                                         .split("-")[1].split(".")[0][:4] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][4:6] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][6:8]),
                                     "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 194292.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 0.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 3124306.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 0.0
    assert result.data['liabilities_and_equity'] == 3718259.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 4870.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 0.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 1317773.0
    assert result.data['net_income_loss'] == 0.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 0.0
    assert result.data['equity_attributable_interest'] == 4352.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 0.0
    assert result.data['income_before_equity_investments'] == 0.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 3718259.0
    assert result.data['gross_profit'] == 0.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 593953.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 0.0
    assert result.data['common_shares_authorized'] == 0.0
Ejemplo n.º 36
0
#! /usr/bin/env python
# encoding: utf-8

from __future__ import print_function

from xbrl import XBRLParser, GAAP, GAAPSerializer, DEISerializer

xbrl_parser = XBRLParser(precision=0)

# Parse an incoming XBRL file
xbrl = xbrl_parser.parse(
    "../../essembly-cli/tests/import_files/Journal_Entry_704171.xml")

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20130629",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)

# Print out the serialized GAAP data
print(result)

# Parse just the DEI data from the xbrl object
dei_obj = xbrl_parser.parseDEI(xbrl)

# Serialize the DEI data
serializer = DEISerializer()
Ejemplo n.º 37
0
#filename = sys.argv[1]
filename = "/Users/thw/test.xml"

#xbrl_import = xml.dom.minidom.parse( filename)

#for record in xbrl_import.getElementsByTagName('ko'):

#	name = record.getAttribute('unitRef')
#	print(record)

#print(str(xbrl_import))

from xbrl import XBRLParser, GAAP, GAAPSerializer

xbrl_parser = XBRLParser()

xbrl = xbrl_parser.parse(filename)

#Revenue = xbrl.find_all(name=re.compile("(fsa:GrossProfitLoss$)", re.IGNORECASE | re.MULTILINE))

Gross_Profit = xbrl.find_all(name=re.compile("(fsa:GrossProfitLoss$)", re.IGNORECASE | re.MULTILINE))

'''
Selling_and_General_Expenses = xbrl.find_all(name=re.compile("(us-gaap:SellingGeneralAndAdministrativeExpense$)", re.IGNORECASE | re.MULTILINE))

Depreciation = xbrl.find_all(name=re.compile("(us-gaap:DepreciationDepletionAndAmortization$)", re.IGNORECASE | re.MULTILINE))

Operating_Income = xbrl.find_all(name=re.compile("(us-gaap:OperatingIncomeLoss$)", re.IGNORECASE | re.MULTILINE))

Interest_Expense = xbrl.find_all(name=re.compile("(us-gaap:InterestExpense$)", re.IGNORECASE | re.MULTILINE))
Ejemplo n.º 38
0
from xbrl import XBRLParser, GAAP, GAAPSerializer

# https://pypi.org/project/python-xbrl/

homedir = '../data/'
addondir = 'xbrl/'
specificfile = 'rf-20190331.xml'

fileLoc = homedir + addondir + specificfile

xbrl_parser = XBRLParser()
xbrl = xbrl_parser.parse(fileLoc)

gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20190401",
                                 context="current",
                                 ignore_errors=0)

# Serialize the GAAP data
serializer = GAAPSerializer()
result = serializer.dump(gaap_obj)
pass
Ejemplo n.º 39
0
#! /usr/bin/env python
# encoding: utf-8

from xbrl import XBRLParser
from xbrl_middleware import ExcelDump, OpenPyxlAdapter

xbrl_parser = XBRLParser(precision=0)

# Parse an incoming XBRL file
xbrl = xbrl_parser.parse(file("sam-20130629.xml"))

# Parse just the GAAP data from the xbrl object
gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20130629",
                                 doc_type="10-Q",
                                 context="current",
                                 ignore_errors=0)

# Dump the GAAP data to XLSX (Excel)
xbrl_dump = ExcelDump(gaap_obj)
dumper = xbrl_middleware.OpenPyxlAdapter(xbrl_dump)
dumper.write('demo.xlsx')
dumper.dump()
Ejemplo n.º 40
0
def test_parse_GAAP10Q_Fujitsu():

    xbrl_parser = XBRLParser()
    file_to_parse = "tests/aaww-20140630.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(
        xbrl,
        str(
            file_to_parse.split("-")[1].split(".")[0][:4] +
            file_to_parse.split("-")[1].split(".")[0][4:6] +
            file_to_parse.split("-")[1].split(".")[0][6:8]), "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 233079.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == -23815.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 414512.0
    assert result.data['non_current_assets'] == 3568474.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 26657.0
    assert result.data['liabilities_and_equity'] == 4100064.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 4870.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 0.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 1355551.0
    assert result.data['net_income_loss'] == 0.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == -515.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == -515.0
    assert result.data['income_before_equity_investments'] == 0.0
    assert result.data['comprehensive_income_interest'] == -515.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 4100064.0
    assert result.data['gross_profit'] == 0.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 531590.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == -612.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 25256124.0
    assert result.data['common_shares_issued'] == 28547138.0
    assert result.data['common_shares_authorized'] == 50000000.0
Ejemplo n.º 41
0
def test_parse_GAAP10Q_Webfilings():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/goog-20140630.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                     str(file_to_parse
                                         .split("-")[1].split(".")[0][:4] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][4:6] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][6:8]),
                                     "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 3683.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 913.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 11697.0
    assert result.data['non_current_assets'] == 43703.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 3490.0
    assert result.data['liabilities_and_equity'] == 121608.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 0.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 95749.0
    assert result.data['net_income_loss'] == 3422.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 3579.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 3579.0
    assert result.data['income_before_equity_investments'] == 4403.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 121608.0
    assert result.data['gross_profit'] == 0.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 77905.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 0.0
    assert result.data['common_shares_authorized'] == 0.0
Ejemplo n.º 42
0
def test_parse_GAAP10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(
        xbrl,
        str(
            file_to_parse.split("-")[1].split(".")[0][:4] +
            file_to_parse.split("-")[1].split(".")[0][4:6] +
            file_to_parse.split("-")[1].split(".")[0][6:8]), "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 98032.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 12107.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 5417.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 19715.0
    assert result.data['liabilities_and_equity'] == 60263.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 65084.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 253536.0
    assert result.data['net_income_loss'] == 19715.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 19715.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 19715.0
    assert result.data['income_before_equity_investments'] == 31822.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 376766.0
    assert result.data['gross_profit'] == 97132.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 138996.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 0.0
Ejemplo n.º 43
0
from xbrl import XBRLParser, GAAPSerializer, DEISerializer

xbrl_parser = XBRLParser()
xbrl = xbrl_parser.parse(open("sample_report/apple-2013-qtr1-10Q-xbrl.xml"))

gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                 doc_date="20121229",
                                 context="current",
                                 ignore_errors=0)
print("Cash generated by operating activities: " +
      str(gaap_obj.net_cash_flows_operating))
print("Cash generated by/(used in) investing activities: " +
      str(gaap_obj.net_cash_flows_investing))
print("Cash used in financing activities: " +
      str(gaap_obj.net_cash_flows_financing))
print("Total shareholders’ equity: " + str(gaap_obj.stockholders_equity))
print("Total assets: " + str(gaap_obj.assets))
print("Operating income: " + str(gaap_obj.operating_income_loss))
print("Net income: " + str(gaap_obj.net_income_loss))
print("Liabilities: " + str(gaap_obj.assets - gaap_obj.stockholders_equity))
print("Total net sales: " + str(gaap_obj.revenues))

dei_obj = xbrl_parser.parseDEI(xbrl)
# Serialize the DEI data
serializer = DEISerializer()
result = serializer.dump(dei_obj)

# serializer = GAAPSerializer()
# result = serializer.dump(gaap_obj)
#
# print(result.data)
Ejemplo n.º 44
0
def test_parse_GAAP10Q_RRDonnelley():

    xbrl_parser = XBRLParser(0)
    file_to_parse = "tests/sam-20130629.xml"
    xbrl = xbrl_parser.parse(file_to_parse)
    gaap_obj = xbrl_parser.parseGAAP(xbrl,
                                     str(file_to_parse
                                         .split("-")[1].split(".")[0][:4] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][4:6] +
                                         file_to_parse.split("-")[1]
                                         .split(".")[0][6:8]),
                                     "current")

    serializer = GAAPSerializer()
    result = serializer.dump(gaap_obj)

    assert result.data['liabilities'] == 98032.0
    assert result.data['net_cash_flows_financing_continuing'] == 0.0
    assert result.data['revenue'] == 0.0
    assert result.data['income_tax_expense_benefit'] == 12107.0
    assert result.data['income_from_equity_investments'] == 0.0
    assert result.data['preferred_stock_dividends'] == 0.0
    assert result.data['redeemable_noncontrolling_interest'] == 0.0
    assert result.data['extraordary_items_gain_loss'] == 0.0
    assert result.data['temporary_equity'] == 0.0
    assert result.data['costs_and_expenses'] == 0.0
    assert result.data['non_current_assets'] == 5417.0
    assert result.data['net_cash_flows_discontinued'] == 0.0
    assert result.data['income_loss'] == 19715.0
    assert result.data['liabilities_and_equity'] == 60263.0
    assert result.data['other_operating_income'] == 0.0
    assert result.data['operating_income_loss'] == 0.0
    assert result.data['net_income_parent'] == 0.0
    assert result.data['equity'] == 0.0
    assert result.data['net_cash_flows_operating_discontinued'] == 0.0
    assert result.data['cost_of_revenue'] == 0.0
    assert result.data['operating_expenses'] == 65084.0
    assert result.data['noncurrent_liabilities'] == 0.0
    assert result.data['current_liabilities'] == 0.0
    assert result.data['net_cash_flows_investing'] == 0.0
    assert result.data['stockholders_equity'] == 253536.0
    assert result.data['net_income_loss'] == 19715.0
    assert result.data['net_cash_flows_investing_continuing'] == 0.0
    assert result.data['nonoperating_income_loss'] == 0.0
    assert result.data['net_cash_flows_financing'] == 0.0
    assert result.data['net_income_shareholders'] == 0.0
    assert result.data['comprehensive_income'] == 19715.0
    assert result.data['equity_attributable_interest'] == 0.0
    assert result.data['commitments_and_contingencies'] == 0.0
    assert result.data['comprehensive_income_parent'] == 19715.0
    assert result.data['income_before_equity_investments'] == 31822.0
    assert result.data['comprehensive_income_interest'] == 0.0
    assert result.data['other_comprehensive_income'] == 0.0
    assert result.data['equity_attributable_parent'] == 0.0
    assert result.data['assets'] == 376766.0
    assert result.data['gross_profit'] == 97132.0
    assert result.data['net_cash_flows_operating_continuing'] == 0.0
    assert result.data['current_assets'] == 138996.0
    assert result.data['interest_and_debt_expense'] == 0.0
    assert result.data['net_income_loss_noncontrolling'] == 0.0
    assert result.data['net_cash_flows_operating'] == 0.0
    assert result.data['common_shares_outstanding'] == 0.0
    assert result.data['common_shares_issued'] == 0.0