From f19950c977efab76ce3816f7fb2530dcf02d9c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=A3=20Bida=20Vacaro?= Date: Mon, 25 Nov 2024 15:02:05 -0300 Subject: [PATCH] linting pt.3 final --- pysus/tests/test_decoders.py | 36 ++++++++++++++++++++++-------------- pysus/tests/test_ftp.py | 29 ++++++++++++++--------------- pysus/tests/test_ibge.py | 12 ++++++------ 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/pysus/tests/test_decoders.py b/pysus/tests/test_decoders.py index 8f3e994..2ced897 100644 --- a/pysus/tests/test_decoders.py +++ b/pysus/tests/test_decoders.py @@ -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 ( @@ -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): @@ -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] ) @@ -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"] @@ -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"] diff --git a/pysus/tests/test_ftp.py b/pysus/tests/test_ftp.py index de98cef..19e1e01 100644 --- a/pysus/tests/test_ftp.py +++ b/pysus/tests/test_ftp.py @@ -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, ) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/pysus/tests/test_ibge.py b/pysus/tests/test_ibge.py index 4623cbc..f20c5fe 100644 --- a/pysus/tests/test_ibge.py +++ b/pysus/tests/test_ibge.py @@ -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__":