From 18b4143d9df1ad5b187be4c3362821f12cdb688c Mon Sep 17 00:00:00 2001 From: jarathomas Date: Wed, 3 Apr 2024 16:14:31 -0400 Subject: [PATCH] change package to src layout; fixed warning messages from changes in pandas --- .github/workflows/python-package.yml | 2 +- MANIFEST.in | 6 +-- pyproject.toml | 48 ++++++++++++++++++ setup.py | 48 +----------------- {interva => src/interva}/__init__.py | 0 {interva => src/interva}/__version__.py | 0 {interva => src/interva}/data/causetext.py | 0 {interva => src/interva}/data/probbase.xls | Bin .../interva}/data/probbaseV5_19.csv | 0 {interva => src/interva}/data/randomva5.csv | 0 {interva => src/interva}/exceptions.py | 0 {interva => src/interva}/interva5.py | 8 +-- {interva => src/interva}/utils.py | 10 ++-- tests/test_compare_r.py | 8 +-- tests/test_utils.py | 2 +- tox.ini | 2 +- 16 files changed, 69 insertions(+), 65 deletions(-) rename {interva => src/interva}/__init__.py (100%) rename {interva => src/interva}/__version__.py (100%) rename {interva => src/interva}/data/causetext.py (100%) rename {interva => src/interva}/data/probbase.xls (100%) rename {interva => src/interva}/data/probbaseV5_19.csv (100%) rename {interva => src/interva}/data/randomva5.csv (100%) rename {interva => src/interva}/exceptions.py (100%) rename {interva => src/interva}/interva5.py (99%) rename {interva => src/interva}/utils.py (98%) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index d91c66b..2c4696e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -18,7 +18,7 @@ jobs: matrix: # os: [ubuntu-latest, macOS-latest, windows-latest] os: [ubuntu-latest] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v1 diff --git a/MANIFEST.in b/MANIFEST.in index b1aa599..b6b85b9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include README.md include LICENSE -include interva/data/*.csv -include interva/data/*.xls -include interva/data/*.py +include src/interva/data/*.csv +include src/interva/data/*.xls +include src/interva/data/*.py diff --git a/pyproject.toml b/pyproject.toml index 638dd9c..dcf2389 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,51 @@ [build-system] requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" + +[project] +name = "interva" +version = "0.0.7" +authors = [ + {name = "Sherry Zhao", email = "zhao.3248@buckeyemail.osu.edu"}, + {name = "Jason Thomas", email = "jarathomas@gmail.com"}, +] +maintainers = [ + {name = "Jason Thomas", email = "jarathomas@gmail.com"}, +] +description = "Python implementation of the InterVA Algorithm." +readme = "README.md" +requires-python = ">=3.8" +keywords = ["verbal autopsy",] +license = {text = "GPLv3"} +classifiers=[ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", +] +dependencies = [ + "pandas", + "numpy", + "vacheck", + "xlrd", +] + +[project.urls] +"Homepage" = "https://github.com/verbal-autopsy-software/interva" +"Bug Tracker" = "https://github.com/verbal-autopsy-software/interva/issues" + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.setuptools.package-data] +"interva.data" = ["*.csv"] + +[tool.pytest.ini_options] +addopts = [ + "--import-mode=importlib", + ] + diff --git a/setup.py b/setup.py index ac13793..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,47 +1,3 @@ -import os -from codecs import open -from setuptools import setup, find_namespace_packages +from setuptools import setup -here = os.path.abspath(os.path.dirname(__file__)) - -about = {} -with open(os.path.join(here, "interva", "__version__.py"), "r", "utf-8") as f: - exec(f.read(), about) - -with open("README.md", "r", "utf-8") as f: - readme = f.read() - - -setup( - name=about["__title__"], - version=about["__version__"], - author=about["__author__"], - author_email=about["__author_email__"], - description=about["__description__"], - long_description=readme, - long_description_content_type="text/markdown", - url=about["__url__"], - license=about["__license__"], - packages=find_namespace_packages(), - include_package_data=True, - package_dir={"": "."}, - package_data={ - "interva.data": ["*.csv", "*.xls"], - }, - install_requires=[ - "pandas", - "xlrd", - "numpy", - "vacheck", - ], - classifiers=[ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Operating System :: OS Independent", - ], -) +setup() diff --git a/interva/__init__.py b/src/interva/__init__.py similarity index 100% rename from interva/__init__.py rename to src/interva/__init__.py diff --git a/interva/__version__.py b/src/interva/__version__.py similarity index 100% rename from interva/__version__.py rename to src/interva/__version__.py diff --git a/interva/data/causetext.py b/src/interva/data/causetext.py similarity index 100% rename from interva/data/causetext.py rename to src/interva/data/causetext.py diff --git a/interva/data/probbase.xls b/src/interva/data/probbase.xls similarity index 100% rename from interva/data/probbase.xls rename to src/interva/data/probbase.xls diff --git a/interva/data/probbaseV5_19.csv b/src/interva/data/probbaseV5_19.csv similarity index 100% rename from interva/data/probbaseV5_19.csv rename to src/interva/data/probbaseV5_19.csv diff --git a/interva/data/randomva5.csv b/src/interva/data/randomva5.csv similarity index 100% rename from interva/data/randomva5.csv rename to src/interva/data/randomva5.csv diff --git a/interva/exceptions.py b/src/interva/exceptions.py similarity index 100% rename from interva/exceptions.py rename to src/interva/exceptions.py diff --git a/interva/interva5.py b/src/interva/interva5.py similarity index 99% rename from interva/interva5.py rename to src/interva/interva5.py index 7ada527..a406175 100644 --- a/interva/interva5.py +++ b/src/interva/interva5.py @@ -553,7 +553,7 @@ def run(self) -> None: comcat = "Multiple" comnum = " " if nanmax(prob_C) >= 0.5: - comcat = prob_C_names[where(prob_C == nanmax(prob_C))[0][0]] + comcat = prob_C_names.iloc[where(prob_C == nanmax(prob_C))[0][0]] comnum = round(nanmax(prob_C) * 100) ID_list[i] = index_current @@ -827,11 +827,11 @@ def get_csmf(self, top: int = 10, dist_cod_sorted.sort_values(ascending=False, inplace=True) # show causes with top non-zero values show_top = 0 - while dist_cod_sorted[show_top] > 0 and show_top < top: + while dist_cod_sorted.iloc[show_top] > 0 and show_top < top: show_top = show_top + 1 if show_top == top: - a = dist_cod_sorted[show_top] - b = dist_cod_sorted[show_top-1] + a = dist_cod_sorted.iloc[show_top] + b = dist_cod_sorted.iloc[show_top-1] while show_top < len(dist_cod_sorted) and \ (abs(a-b) < (a+b) * 1e-5): show_top = show_top + 1 diff --git a/interva/utils.py b/src/interva/utils.py similarity index 98% rename from interva/utils.py rename to src/interva/utils.py index 0d7f1cd..a6b0396 100644 --- a/interva/utils.py +++ b/src/interva/utils.py @@ -195,15 +195,15 @@ def csmf(iva5: interva.interva5.InterVA5, # show causes with top non-zero values show_top = 0 - while dist_cod[show_top] > 0 and show_top < top: + while dist_cod.iloc[show_top] > 0 and show_top < top: show_top = show_top + 1 if show_top == top: - a = dist_cod[show_top] - b = dist_cod[show_top - 1] + a = dist_cod.iloc[show_top] + b = dist_cod.iloc[show_top - 1] while show_top < len(dist_cod) and (abs(a - b) < (a + b) * 1e-5): show_top = show_top + 1 - a = dist_cod[show_top] - b = dist_cod[show_top - 1] + a = dist_cod.iloc[show_top] + b = dist_cod.iloc[show_top - 1] top_csmf = dist_cod.head(show_top) return top_csmf diff --git a/tests/test_compare_r.py b/tests/test_compare_r.py index 2ab358f..50ea7ea 100644 --- a/tests/test_compare_r.py +++ b/tests/test_compare_r.py @@ -57,7 +57,7 @@ def test_r_va5_comparison(): for i in range(r_prob_check.shape[0]): for j in range(r_prob_check.shape[1]): a = round(r_prob_check.iloc[i, j], 10) - b = round(py_prob_check[i][j], 10) + b = round(py_prob_check.iloc[i].iloc[j], 10) assert a == b @@ -67,7 +67,7 @@ def test_r_csmf_top15_comparison(): r_csmf_top15 = r_csmf_top15_check.to_numpy() for i in range(len(r_csmf_top15_check)): a = round(float(py_csmf_top15[i]), 10) - b = round(float(r_csmf_top15[i]), 10) + b = round(float(r_csmf_top15[i][0]), 10) assert a == b @@ -80,7 +80,7 @@ def tests_utils_csmf_1(): r_csmf5_1_top15 = r_csmf5_1_top15.to_numpy() for i in range(len(r_csmf5_1_top15)): a = round(float(py_csmf5_1_top15[i]), 10) - b = round(float(r_csmf5_1_top15[i]), 10) + b = round(float(r_csmf5_1_top15[i][0]), 10) assert a == b @@ -93,5 +93,5 @@ def tests_utils_csmf_2(): r_csmf5_2_top15 = r_csmf5_2_top15.to_numpy() for i in range(len(r_csmf5_2_top15)): a = round(float(py_csmf5_2_top15[i]), 4) - b = round(float(r_csmf5_2_top15[i]), 4) + b = round(float(r_csmf5_2_top15[i][0]), 4) assert a == b diff --git a/tests/test_utils.py b/tests/test_utils.py index 22f82f6..b35d4a6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -27,7 +27,7 @@ def make_age_test_data(age_group, yes, no): sex_groups = Series({"ID": "d1", "i019a": "y", "i019b": "n"}) - age_groups = Series({f"i022{i}": no for i in age_letters}) + age_groups = Series({f"i022{i}": no for i in age_letters}).astype(object) age_groups[age_group] = yes va_record = concat([sex_groups, age_groups]) age_all, age = all_age_groups[age_group] diff --git a/tox.ini b/tox.ini index d067b2f..23f9181 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py37, py38, py39, py310, py311 +envlist = py38, py38, py39, py310, py311, py312 [testenv] deps =