polarstate 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polarstate-0.1.0/.github/workflows/python-package.yml +49 -0
- polarstate-0.1.0/.gitignore +10 -0
- polarstate-0.1.0/.python-version +1 -0
- polarstate-0.1.0/PKG-INFO +7 -0
- polarstate-0.1.0/README.md +0 -0
- polarstate-0.1.0/pyproject.toml +30 -0
- polarstate-0.1.0/src/polarstate/__init__.py +6 -0
- polarstate-0.1.0/src/polarstate/aj.py +20 -0
- polarstate-0.1.0/tests/test_polarstate.py +29 -0
- polarstate-0.1.0/uv.lock +91 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: Python package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ "master" ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ "master" ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v5
|
|
20
|
+
|
|
21
|
+
- name: Create virtual environment
|
|
22
|
+
run: uv venv
|
|
23
|
+
|
|
24
|
+
- name: Run tests using uv
|
|
25
|
+
run: uv run pytest tests
|
|
26
|
+
|
|
27
|
+
publish:
|
|
28
|
+
name: Upload release to PyPI
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
needs: build
|
|
31
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
32
|
+
environment: pypi
|
|
33
|
+
permissions:
|
|
34
|
+
id-token: write
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
|
|
39
|
+
- name: Install uv
|
|
40
|
+
uses: astral-sh/setup-uv@v5
|
|
41
|
+
|
|
42
|
+
- name: Create virtual environment
|
|
43
|
+
run: uv venv
|
|
44
|
+
|
|
45
|
+
- name: Build package using uv
|
|
46
|
+
run: uv build
|
|
47
|
+
|
|
48
|
+
- name: Publish package using uv
|
|
49
|
+
run: uv publish
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "polarstate"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Uriah Finkel", email = "Ufinkel@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.13"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"polars>=1.29.0",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
polarstate = "polarstate:main"
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["hatchling"]
|
|
19
|
+
build-backend = "hatchling.build"
|
|
20
|
+
|
|
21
|
+
[dependency-groups]
|
|
22
|
+
dev = [
|
|
23
|
+
"polars>=1.29.0",
|
|
24
|
+
"pytest>=8.3.5",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.pytest.ini_options]
|
|
28
|
+
testpaths = ["tests"]
|
|
29
|
+
python_files = "test_*.py"
|
|
30
|
+
python_functions = "test_*"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
|
|
3
|
+
def aalen_johansen(times: pl.Series, reals: pl.Series, event_of_interest: int = 1, competing_events: list[int] = [2]) -> pl.DataFrame:
|
|
4
|
+
df = pl.DataFrame({"times": times, "reals": reals})
|
|
5
|
+
df = df.sort("times")
|
|
6
|
+
|
|
7
|
+
event_times = df.filter(pl.col("reals") != 0)["times"].unique().sort()
|
|
8
|
+
result = []
|
|
9
|
+
cum_hazard = 0.0
|
|
10
|
+
|
|
11
|
+
for t in event_times:
|
|
12
|
+
n_at_risk = df.filter(pl.col("times") >= t).height
|
|
13
|
+
n_event = df.filter((pl.col("times") == t) & (pl.col("reals") == event_of_interest)).height
|
|
14
|
+
|
|
15
|
+
if n_at_risk > 0:
|
|
16
|
+
hazard = n_event / n_at_risk
|
|
17
|
+
cum_hazard += hazard
|
|
18
|
+
result.append({"time": t, "cuminc": cum_hazard})
|
|
19
|
+
|
|
20
|
+
return pl.DataFrame(result)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
from polarstate.aj import aalen_johansen
|
|
3
|
+
|
|
4
|
+
def test_aalen_johansen() -> None:
|
|
5
|
+
# Test data
|
|
6
|
+
times = pl.Series([1, 2, 3, 4, 5])
|
|
7
|
+
reals = pl.Series([1, 0, 2, 1, 0])
|
|
8
|
+
|
|
9
|
+
# Expected output
|
|
10
|
+
expected_output = pl.DataFrame({
|
|
11
|
+
"time": [1, 2, 3],
|
|
12
|
+
"cuminc": [0.5, 0.5, 0.6666666666666666]
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
# Call the function
|
|
16
|
+
result = aalen_johansen(times, reals)
|
|
17
|
+
|
|
18
|
+
# Check if the result is a DataFrame
|
|
19
|
+
assert isinstance(result, pl.DataFrame), "Result is not a DataFrame"
|
|
20
|
+
# Check if the result has the correct columns
|
|
21
|
+
assert set(result.columns) == {"time", "cuminc"}, f"Expected columns {'time', 'cuminc'} but got {result.columns}"
|
|
22
|
+
# Check if the result has the correct number of rows
|
|
23
|
+
assert len(result) == 3, f"Expected 3 rows but got {len(result)}"
|
|
24
|
+
# Check if the result is sorted by time
|
|
25
|
+
assert result["time"].is_sorted(), "Result is not sorted by time"
|
|
26
|
+
# Check if the cumulative incidence is non-decreasing
|
|
27
|
+
assert all(result["cuminc"].to_list()[i] <= result["cuminc"].to_list()[i + 1] for i in range(len(result) - 1)), "Cumulative incidence is not non-decreasing"
|
|
28
|
+
|
|
29
|
+
|
polarstate-0.1.0/uv.lock
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
version = 1
|
|
2
|
+
revision = 1
|
|
3
|
+
requires-python = ">=3.13"
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "colorama"
|
|
7
|
+
version = "0.4.6"
|
|
8
|
+
source = { registry = "https://pypi.org/simple" }
|
|
9
|
+
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697 }
|
|
10
|
+
wheels = [
|
|
11
|
+
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335 },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "iniconfig"
|
|
16
|
+
version = "2.1.0"
|
|
17
|
+
source = { registry = "https://pypi.org/simple" }
|
|
18
|
+
sdist = { url = "https://files.pythonhosted.org/packages/f2/97/ebf4da567aa6827c909642694d71c9fcf53e5b504f2d96afea02718862f3/iniconfig-2.1.0.tar.gz", hash = "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7", size = 4793 }
|
|
19
|
+
wheels = [
|
|
20
|
+
{ url = "https://files.pythonhosted.org/packages/2c/e1/e6716421ea10d38022b952c159d5161ca1193197fb744506875fbb87ea7b/iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760", size = 6050 },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "packaging"
|
|
25
|
+
version = "25.0"
|
|
26
|
+
source = { registry = "https://pypi.org/simple" }
|
|
27
|
+
sdist = { url = "https://files.pythonhosted.org/packages/a1/d4/1fc4078c65507b51b96ca8f8c3ba19e6a61c8253c72794544580a7b6c24d/packaging-25.0.tar.gz", hash = "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f", size = 165727 }
|
|
28
|
+
wheels = [
|
|
29
|
+
{ url = "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl", hash = "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", size = 66469 },
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "pluggy"
|
|
34
|
+
version = "1.6.0"
|
|
35
|
+
source = { registry = "https://pypi.org/simple" }
|
|
36
|
+
sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412 }
|
|
37
|
+
wheels = [
|
|
38
|
+
{ url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538 },
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "polars"
|
|
43
|
+
version = "1.29.0"
|
|
44
|
+
source = { registry = "https://pypi.org/simple" }
|
|
45
|
+
sdist = { url = "https://files.pythonhosted.org/packages/0b/92/8d0e80fef779a392b1a736b554ffba62403026bad7df8a9de8b61dce018f/polars-1.29.0.tar.gz", hash = "sha256:d2acb71fce1ff0ea76db5f648abd91a7a6c460fafabce9a2e8175184efa00d02", size = 4582973 }
|
|
46
|
+
wheels = [
|
|
47
|
+
{ url = "https://files.pythonhosted.org/packages/e7/5f/b277179cfce1258fecf4ad73cf627f670be41fdf088727090f68ca9c96ff/polars-1.29.0-cp39-abi3-macosx_10_12_x86_64.whl", hash = "sha256:d053ee3217df31468caf2f5ddb9fd0f3a94fd42afdf7d9abe23d9d424adca02b", size = 34206809 },
|
|
48
|
+
{ url = "https://files.pythonhosted.org/packages/34/e7/634e5cb55ce8bef23ac8ad8e3834c9045f4b3cbdff1fb9e7826d864436e6/polars-1.29.0-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:14131078e365eae5ccda3e67383cd43c0c0598d7f760bdf1cb4082566c5494ce", size = 31100055 },
|
|
49
|
+
{ url = "https://files.pythonhosted.org/packages/50/15/0e9072e410731980ebc567c60a0a5f02bc2183310e48704ef83682cdd54c/polars-1.29.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:54f6902da333f99208b8d27765d580ba0299b412787c0564275912122c228e40", size = 34828438 },
|
|
50
|
+
{ url = "https://files.pythonhosted.org/packages/69/c0/90fcaac5c95aa225b3899698289c0424d429ef72248b593f15294f95a35e/polars-1.29.0-cp39-abi3-manylinux_2_24_aarch64.whl", hash = "sha256:7a0ac6a11088279af4d715f4b58068835f551fa5368504a53401743006115e78", size = 32073830 },
|
|
51
|
+
{ url = "https://files.pythonhosted.org/packages/17/ed/e5e570e22a03549a3c5397035a006b2c6343856a9fd15cccb5db39bdfa0a/polars-1.29.0-cp39-abi3-win_amd64.whl", hash = "sha256:f5aac4656e58b1e12f9481950981ef68b5b0e53dd4903bd72472efd2d09a74c8", size = 34971841 },
|
|
52
|
+
{ url = "https://files.pythonhosted.org/packages/45/fd/9039f609d76b3ebb13777f289502a00b52709aea5c35aed01d1090ac142f/polars-1.29.0-cp39-abi3-win_arm64.whl", hash = "sha256:0c105b07b980b77fe88c3200b015bf4695e53185385f0f244c13e2d1027c7bbf", size = 31298689 },
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[[package]]
|
|
56
|
+
name = "polarstate"
|
|
57
|
+
version = "0.1.0"
|
|
58
|
+
source = { editable = "." }
|
|
59
|
+
dependencies = [
|
|
60
|
+
{ name = "polars" },
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
[package.dev-dependencies]
|
|
64
|
+
dev = [
|
|
65
|
+
{ name = "polars" },
|
|
66
|
+
{ name = "pytest" },
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[package.metadata]
|
|
70
|
+
requires-dist = [{ name = "polars", specifier = ">=1.29.0" }]
|
|
71
|
+
|
|
72
|
+
[package.metadata.requires-dev]
|
|
73
|
+
dev = [
|
|
74
|
+
{ name = "polars", specifier = ">=1.29.0" },
|
|
75
|
+
{ name = "pytest", specifier = ">=8.3.5" },
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[[package]]
|
|
79
|
+
name = "pytest"
|
|
80
|
+
version = "8.3.5"
|
|
81
|
+
source = { registry = "https://pypi.org/simple" }
|
|
82
|
+
dependencies = [
|
|
83
|
+
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
|
84
|
+
{ name = "iniconfig" },
|
|
85
|
+
{ name = "packaging" },
|
|
86
|
+
{ name = "pluggy" },
|
|
87
|
+
]
|
|
88
|
+
sdist = { url = "https://files.pythonhosted.org/packages/ae/3c/c9d525a414d506893f0cd8a8d0de7706446213181570cdbd766691164e40/pytest-8.3.5.tar.gz", hash = "sha256:f4efe70cc14e511565ac476b57c279e12a855b11f48f212af1080ef2263d3845", size = 1450891 }
|
|
89
|
+
wheels = [
|
|
90
|
+
{ url = "https://files.pythonhosted.org/packages/30/3d/64ad57c803f1fa1e963a7946b6e0fea4a70df53c1a7fed304586539c2bac/pytest-8.3.5-py3-none-any.whl", hash = "sha256:c69214aa47deac29fad6c2a4f590b9c4a9fdb16a403176fe154b79c0b4d4d820", size = 343634 },
|
|
91
|
+
]
|