Skip to content

Commit

Permalink
linting pt.3 final
Browse files Browse the repository at this point in the history
  • Loading branch information
luabida committed Nov 25, 2024
1 parent 3df93af commit f19950c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
36 changes: 22 additions & 14 deletions pysus/tests/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
import pandas as pd
import pytest
from numpy.testing import *
from numpy.testing import * # noqa
from pysus.online_data.SIM import download, get_CID10_chapters_table
from pysus.preprocessing import decoders
from pysus.preprocessing.SIM import (
Expand Down Expand Up @@ -43,28 +43,36 @@ def test_decodifica_idade_retorna_em_anos(self):
@pytest.mark.timeout(10)
def test_decodifica_lista_idades_retorna_em_anos(self):
res = decoders.decodifica_idade_SINAN([4010] * 3, unidade="Y")
assert_array_equal(res, np.array([10] * 3))
assert_array_equal(res, np.array([10] * 3)) # noqa
res = decoders.decodifica_idade_SINAN([3120] * 4, unidade="Y")
assert_array_equal(res, np.array([10] * 4))
assert_array_equal(res, np.array([10] * 4)) # noqa
res = decoders.decodifica_idade_SINAN([2365] * 2, unidade="Y")
assert_array_equal(res, np.array([1, 1]))
assert_array_equal(res, np.array([1, 1])) # noqa
res = decoders.decodifica_idade_SINAN([1480] * 5, unidade="Y")
assert_array_almost_equal(res, np.array([0.0547] * 5), decimal=3)
assert_array_almost_equal( # noqa
res, np.array([0.0547] * 5), decimal=3
) # noqa

@pytest.mark.timeout(10)
def test_decodifica_idade_retorna_em_anos_SIM(self):
res = decoders.decodifica_idade_SIM(["501"], unidade="Y")
assert_array_equal(res, np.array([101]))
assert_array_equal(res, np.array([101])) # noqa
res = decoders.decodifica_idade_SIM(["401"] * 2, unidade="Y")
assert_array_equal(res, np.array([1] * 2))
assert_array_equal(res, np.array([1] * 2)) # noqa
res = decoders.decodifica_idade_SIM(["311"] * 3, unidade="Y")
assert_array_almost_equal(res, np.array([0.904109589] * 3), decimal=3)
assert_array_almost_equal( # noqa
res, np.array([0.904109589] * 3), decimal=3
) # noqa
res = decoders.decodifica_idade_SIM(["224"] * 4, unidade="Y")
assert_array_almost_equal(res, np.array([0.065753425] * 4), decimal=3)
assert_array_almost_equal( # noqa
res, np.array([0.065753425] * 4), decimal=3
) # noqa
res = decoders.decodifica_idade_SIM(["130"] * 5, unidade="Y")
assert_array_almost_equal(res, np.array([0.00274] * 5), decimal=3)
assert_array_almost_equal( # noqa
res, np.array([0.00274] * 5), decimal=3
) # noqa
res = decoders.decodifica_idade_SIM(["010"] * 6, unidade="m")
assert_array_almost_equal(res, np.array([10.0] * 6))
assert_array_almost_equal(res, np.array([10.0] * 6)) # noqa

@pytest.mark.timeout(10)
def test_verifica_geocodigo(self):
Expand Down Expand Up @@ -106,7 +114,7 @@ def test_get_cid_chapter(self):
results = test_causes["causas"].map(
lambda x: get_CID10_code(code_index, x)
)
assert_array_equal(
assert_array_equal( # noqa
results, [1, 1, 2, -1, 3, 7, 7, 8, -1, 20, 20, -1, 22]
)

Expand Down Expand Up @@ -136,7 +144,7 @@ def test_redistribute(self):
counts = redistribute_missing(counts, variables)
sum_redistributed = counts["COUNTS"].sum()

assert_almost_equal(sum_original, sum_redistributed, 10)
assert_almost_equal(sum_original, sum_redistributed, 10) # noqa

sample = (
counts[counts["COUNTS"] != 0]["COUNTS"]
Expand All @@ -150,7 +158,7 @@ def test_redistribute(self):
)
sum_redistributed = counts["COUNTS"].sum()

assert_almost_equal(sum_original, sum_redistributed, 10)
assert_almost_equal(sum_original, sum_redistributed, 10) # noqa

sample = (
counts[counts["COUNTS"] != 0]["COUNTS"]
Expand Down
29 changes: 14 additions & 15 deletions pysus/tests/test_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
from pathlib import Path

import pandas as pd

from pysus.ftp import File, Directory, Database, CACHE
from pysus.data.local import ParquetSet
from pysus.ftp import CACHE, Database, Directory, File
from pysus.ftp.databases import (
ciha,
cnes,
pni,
ibge_datasus,
sinan,
sih,
sinasc,
pni,
sia,
sih,
sim,
sinan,
sinasc,
)


Expand Down Expand Up @@ -79,7 +78,7 @@ def test_ciha(self):
self.assertTrue(database.name == "CIHA")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'month', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "month", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 4)

Expand All @@ -89,7 +88,7 @@ def test_cnes(self):
self.assertTrue(database.name == "CNES")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'month', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "month", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 4)

Expand All @@ -99,7 +98,7 @@ def test_pni(self):
self.assertTrue(database.name == "PNI")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 3)

Expand All @@ -109,7 +108,7 @@ def test_ibge_datasus(self):
self.assertTrue(database.name == "IBGE-DataSUS")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'last_update', 'name', 'size', 'year'}
{"last_update", "name", "size", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 1)

Expand All @@ -119,7 +118,7 @@ def test_sinan(self):
self.assertTrue(database.name == "SINAN")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'disease', 'last_update', 'name', 'size', 'year'}
{"disease", "last_update", "name", "size", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 2)

Expand All @@ -129,7 +128,7 @@ def test_sih(self):
self.assertTrue(database.name == "SIH")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'month', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "month", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 4)

Expand All @@ -139,7 +138,7 @@ def test_sinasc(self):
self.assertTrue(database.name == "SINASC")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 3)

Expand All @@ -149,7 +148,7 @@ def test_sia(self):
self.assertTrue(database.name == "SIA")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'month', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "month", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 4)

Expand All @@ -159,6 +158,6 @@ def test_sim(self):
self.assertTrue(database.name == "SIM")
self.assertSetEqual(
set(database.describe(database.files[0])),
{'group', 'last_update', 'name', 'size', 'uf', 'year'}
{"group", "last_update", "name", "size", "uf", "year"},
)
self.assertEqual(len(database.format(database.files[0])), 3)
12 changes: 6 additions & 6 deletions pysus/tests/test_ibge.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def test_FetchData(self):

@pytest.mark.timeout(120)
def test_get_population(self):
l = IBGE.get_population(year=2021, source="POP")
self.assertEqual(type(l), pd.DataFrame)
self.assertEqual(len(l), 5570)
l = IBGE.get_population(year=2012, source="projpop")
self.assertEqual(type(l), pd.DataFrame)
self.assertEqual(len(l), 182)
l1 = IBGE.get_population(year=2021, source="POP")
self.assertEqual(type(l1), pd.DataFrame)
self.assertEqual(len(l1), 5570)
l2 = IBGE.get_population(year=2012, source="projpop")
self.assertEqual(type(l2), pd.DataFrame)
self.assertEqual(len(l2), 182)


if __name__ == "__main__":
Expand Down

0 comments on commit f19950c

Please sign in to comment.