Exemplo n.º 1
0
def test_metadata_split_to_dict():
    """Should split metadata into a dictionary."""
    pc_axis = pyaxis.read(data_path + '14001.px', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    assert type(metadata) == dict
    assert len(metadata) == 28
Exemplo n.º 2
0
def test_metadata_split_dict_quotation_marks():
    """Should ignore character split if it is between quotation marks."""
    metadata_elements = [
        'VALUES("estrato de empleo")="Total",">=10 empleados";'
    ]
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    assert type(metadata) == dict
    assert metadata['VALUES(estrato de empleo)'] == ['Total', '>=10 empleados']
Exemplo n.º 3
0
def test_metadata_split_to_dict():
    """Should split metadata into a dictionary."""
    pc_axis = pyaxis.read(
        'https://www.ine.es/jaxi/files/_px/es/px/t20/e301/matri/a2000/l0/'
        '14001.px?nocab=1', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    assert type(metadata) == dict
    assert len(metadata) == 23
Exemplo n.º 4
0
def test_get_codes():
    """Should return two lists (dimension names with codes and codes)."""
    pc_axis = pyaxis.read(data_path + '14001.px', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    dimensions_with_codes, dimension_codes = pyaxis.get_codes(metadata)
    assert len(dimension_codes) == 1
    assert len(dimensions_with_codes) == 1
    assert dimensions_with_codes[
        0] == 'Comunidad Autónoma de residencia del matrimonio'
    assert dimension_codes[0][6] == 'CA06'
    assert dimension_codes[0][11] == 'CA11'
Exemplo n.º 5
0
def test_get_dimensions():
    """Should return two lists (dimension names and members)."""
    pc_axis = pyaxis.read(data_path + '14001.px', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    dimension_names, dimension_members = pyaxis.get_dimensions(metadata)
    assert len(dimension_names) == 4
    assert dimension_names[
        0] == 'Comunidad Autónoma de residencia del matrimonio'
    assert dimension_names[3] == 'estado civil anterior de los cónyuges'
    assert len(dimension_members) == 4
    assert dimension_members[0][0] == 'Total'
    assert dimension_members[3][3] == 'Divorciados/as'
Exemplo n.º 6
0
def test_get_dimensions():
    """Should return two lists (dimension names and members)."""
    pc_axis = pyaxis.read(
        'https://www.ine.es/jaxi/files/_px/es/px/t20/e301/matri/a2000/l0/'
        '14001.px?nocab=1', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    dimension_names, dimension_members = pyaxis.get_dimensions(metadata)
    assert len(dimension_names) == 4
    assert dimension_names[
        0] == 'Comunidad Autónoma de residencia de los cónyuges'
    assert dimension_names[3] == 'Estado civil anterior de los cónyuges'
    assert len(dimension_members) == 4
    assert dimension_members[0][0] == 'Todas las comunidades'
    assert dimension_members[3][3] == 'Divorciados/as'
Exemplo n.º 7
0
def test_build_dataframe():
    """Should return a dataframe with n+1 columns (dimensions + data)."""
    null_values = r'^"\."$'
    sd_values = r'"\.\."'
    pc_axis = pyaxis.read(data_path + '14001.px', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    dimension_names, dimension_members = pyaxis.get_dimensions(metadata)
    data_values = Series(raw_data.split())
    df = pyaxis.build_dataframe(dimension_names,
                                dimension_members,
                                data_values,
                                null_values=null_values,
                                sd_values=sd_values)
    assert df.shape == (8064, 5)
    assert df['DATA'][7] == '28138'
    assert df['DATA'][159] == '422'
Exemplo n.º 8
0
def test_build_dataframe():
    """Should return a dataframe with n+1 columns (dimensions + data)."""
    null_values = r'^"\."$'
    sd_values = r'"\.\."'
    pc_axis = pyaxis.read(
        'https://www.ine.es/jaxi/files/_px/es/px/t20/e301/matri/a2000/l0/'
        '14001.px?nocab=1', 'iso-8859-15')
    metadata_elements, raw_data = pyaxis.metadata_extract(pc_axis)
    metadata = pyaxis.metadata_split_to_dict(metadata_elements)
    dimension_names, dimension_members = pyaxis.get_dimensions(metadata)
    data_values = Series(raw_data.split())
    df = pyaxis.build_dataframe(dimension_names,
                                dimension_members,
                                data_values,
                                null_values=null_values,
                                sd_values=sd_values)
    assert df.shape == (8064, 5)
    assert df['DATA'][7] == '10624.0'
    assert df['DATA'][159] == '534.0'