hypors 0.4.1__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.
Files changed (63) hide show
  1. hypors-0.4.1/.gitignore +22 -0
  2. hypors-0.4.1/CHANGELOG.md +100 -0
  3. hypors-0.4.1/Cargo.toml +25 -0
  4. hypors-0.4.1/LICENSE +21 -0
  5. hypors-0.4.1/PKG-INFO +93 -0
  6. hypors-0.4.1/README.md +124 -0
  7. hypors-0.4.1/pyproject.toml +27 -0
  8. hypors-0.4.1/python/Cargo.lock +439 -0
  9. hypors-0.4.1/python/Cargo.toml +22 -0
  10. hypors-0.4.1/python/README.md +76 -0
  11. hypors-0.4.1/python/src/anova.rs +30 -0
  12. hypors-0.4.1/python/src/chi_square.rs +80 -0
  13. hypors-0.4.1/python/src/convert.rs +103 -0
  14. hypors-0.4.1/python/src/lib.rs +56 -0
  15. hypors-0.4.1/python/src/mann_whitney.rs +30 -0
  16. hypors-0.4.1/python/src/proportion.rs +51 -0
  17. hypors-0.4.1/python/src/t.rs +68 -0
  18. hypors-0.4.1/python/src/types.rs +138 -0
  19. hypors-0.4.1/python/src/z.rs +71 -0
  20. hypors-0.4.1/python/tests/conftest.py +10 -0
  21. hypors-0.4.1/python/tests/pytest.ini +5 -0
  22. hypors-0.4.1/python/tests/test_anova.py +32 -0
  23. hypors-0.4.1/python/tests/test_chi_square.py +54 -0
  24. hypors-0.4.1/python/tests/test_common.py +79 -0
  25. hypors-0.4.1/python/tests/test_inputs.py +64 -0
  26. hypors-0.4.1/python/tests/test_mann_whitney.py +76 -0
  27. hypors-0.4.1/python/tests/test_proportion.py +35 -0
  28. hypors-0.4.1/python/tests/test_t.py +51 -0
  29. hypors-0.4.1/python/tests/test_z.py +39 -0
  30. hypors-0.4.1/src/anova/mod.rs +34 -0
  31. hypors-0.4.1/src/anova/one_way.rs +111 -0
  32. hypors-0.4.1/src/anova/sample_size.rs +44 -0
  33. hypors-0.4.1/src/chi_square/categorical.rs +207 -0
  34. hypors-0.4.1/src/chi_square/mod.rs +50 -0
  35. hypors-0.4.1/src/chi_square/sample_size.rs +132 -0
  36. hypors-0.4.1/src/chi_square/variance.rs +99 -0
  37. hypors-0.4.1/src/common/calc.rs +122 -0
  38. hypors-0.4.1/src/common/errors.rs +127 -0
  39. hypors-0.4.1/src/common/mod.rs +33 -0
  40. hypors-0.4.1/src/common/types.rs +52 -0
  41. hypors-0.4.1/src/common/utils.rs +28 -0
  42. hypors-0.4.1/src/lib.rs +202 -0
  43. hypors-0.4.1/src/mann_whitney/mod.rs +24 -0
  44. hypors-0.4.1/src/mann_whitney/u.rs +170 -0
  45. hypors-0.4.1/src/proportion/mod.rs +36 -0
  46. hypors-0.4.1/src/proportion/one_sample.rs +100 -0
  47. hypors-0.4.1/src/proportion/sample_size.rs +45 -0
  48. hypors-0.4.1/src/proportion/two_sample.rs +111 -0
  49. hypors-0.4.1/src/t/mod.rs +38 -0
  50. hypors-0.4.1/src/t/one_sample.rs +134 -0
  51. hypors-0.4.1/src/t/sample_size.rs +57 -0
  52. hypors-0.4.1/src/t/two_sample.rs +260 -0
  53. hypors-0.4.1/src/z/mod.rs +39 -0
  54. hypors-0.4.1/src/z/one_sample.rs +156 -0
  55. hypors-0.4.1/src/z/sample_size.rs +56 -0
  56. hypors-0.4.1/src/z/two_sample.rs +302 -0
  57. hypors-0.4.1/tests/anova.rs +61 -0
  58. hypors-0.4.1/tests/chi_square.rs +146 -0
  59. hypors-0.4.1/tests/common.rs +187 -0
  60. hypors-0.4.1/tests/mann_whitney.rs +155 -0
  61. hypors-0.4.1/tests/proportion.rs +86 -0
  62. hypors-0.4.1/tests/t.rs +121 -0
  63. hypors-0.4.1/tests/z.rs +110 -0
@@ -0,0 +1,22 @@
1
+ # Rust
2
+
3
+ ## Cargo compilations
4
+ debug/
5
+ target/
6
+
7
+ # Cargo files
8
+ Cargo.lock
9
+ **/*.rs.bk
10
+
11
+ # Python
12
+
13
+ ## Cache
14
+ __pycache__
15
+ .pytest_cache
16
+
17
+ ## Virtual Environment
18
+ hypenv/
19
+
20
+ # Other
21
+
22
+ notes.txt
@@ -0,0 +1,100 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file. The format
4
+ follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
+
6
+ While this crate is pre-1.0, the **minor** version carries breaking changes:
7
+ a dependency on `0.3` will not resolve to `0.4`.
8
+
9
+ ## [Unreleased]
10
+
11
+ Nothing yet. Add entries here as they land; move them under a new version
12
+ heading when releasing, since the release workflow takes its GitHub Release
13
+ notes from the section matching the tag.
14
+
15
+ ## [0.4.1] - 2026-09-13
16
+
17
+ The first release of the Python package. It ships at 0.4.1 rather than 0.4.0
18
+ because versions track the crate, and the `v0.4.0` tag predates the bindings —
19
+ there is no Python package in that tree to publish.
20
+
21
+ ### Added
22
+
23
+ - **Python bindings** (`python/`), published to PyPI as `hypors` and versioned
24
+ in lockstep with this crate. All 20 public test and sample-size functions are
25
+ exposed across `hypors.t`, `hypors.z`, `hypors.proportion`, `hypors.anova`,
26
+ `hypors.chi_square` and `hypors.mann_whitney`, with `TailType` and
27
+ `TestResult` in `hypors.common` and at the top level.
28
+ - Any Python iterable of numbers is accepted — list, tuple, generator,
29
+ `numpy` array, `pandas`/`polars` Series — and the package depends on none
30
+ of them.
31
+ - `StatError` surfaces as `ValueError` for empty or insufficient data and
32
+ `RuntimeError` for a failed computation.
33
+ - The pytest suite asserts the same fixture values as the Rust integration
34
+ tests, so both layers are held to the scipy-verified numbers.
35
+ - CI builds the wheel, lints the binding crate and runs the Python suite.
36
+ - The release workflow now publishes both registries from one `vX.Y.Z` tag:
37
+ wheels for Linux, macOS and Windows plus a source distribution go to PyPI
38
+ behind the `pypi` environment, alongside the existing crates.io publish.
39
+ Each registry is skipped if it already holds the version, so a release can
40
+ be re-run, and `workflow_dispatch` allows running against an existing tag.
41
+ The version guard now checks all three manifests agree with the tag.
42
+
43
+ ### Changed
44
+
45
+ - The crate no longer builds a `cdylib`. It was a leftover from an earlier
46
+ attempt at putting the bindings in this crate, produced a `libhypors.so`
47
+ nothing consumed, and collided with the extension module's output filename.
48
+
49
+ ## [0.4.0] - 2026-09-07
50
+
51
+ ### Changed
52
+
53
+ - **Mann-Whitney U p-values now match `scipy.stats.mannwhitneyu`
54
+ (`method="asymptotic"`).** Existing p-values change, and one-sided results
55
+ change substantially. Thanks to @guilherme-n-l (#7, reported in #6).
56
+ - The variance carries the tie correction
57
+ `n1*n2/12 * ((N + 1) - sum(t^3 - t) / (N * (N - 1)))`. The previous
58
+ no-ties variance overestimated sigma and inflated p-values on tied data.
59
+ - A 0.5 continuity correction is applied toward the tail, matching scipy's
60
+ default `use_continuity=True`.
61
+ - One-sided p-values derive from `U1` rather than `min(U1, U2)`. The old
62
+ statistic was sign-blind, so `TailType::Right` and `TailType::Left`
63
+ returned identical p-values regardless of which group dominated.
64
+ - When every observation is tied the variance is zero: the two-sided
65
+ p-value is now `NaN` and the one-sided p-values are `1.0`, matching
66
+ scipy 1.18's signed continuity correction. Previously this returned
67
+ `1.0` two-sided and `0.5` one-sided.
68
+ - `test_statistic` is documented explicitly as `min(U1, U2)` while the
69
+ p-value derives from `U1`, so compare p-values rather than statistics
70
+ when checking against scipy.
71
+ - **`mann_whitney::u_test` and `chi_square::variance` now return
72
+ `Result<TestResult, StatError>`** instead of `Result<TestResult, String>`,
73
+ matching every other test in the crate. Code matching on the error needs
74
+ updating; code using `?` or `unwrap()` does not. Empty input now yields
75
+ `StatError::EmptyData`, too few observations `StatError::InsufficientData`,
76
+ and distribution failures `StatError::ComputeError`.
77
+
78
+ ### Added
79
+
80
+ - `rust-version = "1.85"`, the minimum supported Rust version for
81
+ edition 2024.
82
+ - GitHub Actions CI running `cargo fmt --check`,
83
+ `cargo clippy --all-targets -- -D warnings`, `cargo test` (doc tests
84
+ included) and `cargo package` on every pull request (#8, #9).
85
+
86
+ ### Fixed
87
+
88
+ - The manifest is named `Cargo.toml` rather than `cargo.toml`, which only
89
+ resolved on case-insensitive filesystems and broke every cargo command on
90
+ Linux (#8).
91
+
92
+ ### Internal
93
+
94
+ - The published crate no longer ships the Python bindings (`hypopy`),
95
+ `py_tests`, or the CI configuration — 54 files down to 41 (#8).
96
+
97
+ ## [0.3.0] - 2025-04-19
98
+
99
+ See the [release history](https://github.com/astronights/hypors/releases) for
100
+ versions before this changelog was introduced.
@@ -0,0 +1,25 @@
1
+ [package]
2
+ name = "hypors"
3
+ authors = ["Shubhankar Agrawal <shubhankar.a31@gmail.com>"]
4
+ version = "0.4.1"
5
+ edition = "2024"
6
+ rust-version = "1.85" # edition 2024 requires 1.85+
7
+ license-file = "LICENSE"
8
+ repository = "https://github.com/astronights/hypors"
9
+ description = "Hypothesis Testing with Rust"
10
+ keywords = ["statistics", "hypothesis", "testing", "data", "p-value"]
11
+
12
+ # Keep the published crate to the Rust library: the Python bindings
13
+ # (which carry their own manifest and pyproject.toml), their tests, and
14
+ # the CI config are of no use to a crates.io consumer.
15
+ exclude = [".github", "python"]
16
+ readme = "README.md"
17
+
18
+ [lib]
19
+ name = "hypors"
20
+ path = "src/lib.rs"
21
+ crate-type = ["lib"]
22
+
23
+ [dependencies]
24
+ serde = {version = ">=1.0.210", features = ["derive"]}
25
+ statrs = ">=0.17.1"
hypors-0.4.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Shubhankar Agrawal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
hypors-0.4.1/PKG-INFO ADDED
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: hypors
3
+ Version: 0.4.1
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Python :: Implementation :: CPython
7
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
8
+ Summary: Hypothesis testing for Python, backed by the hypors Rust crate
9
+ Keywords: statistics,hypothesis,testing,p-value
10
+ Author-email: Shubhankar Agrawal <shubhankar.a31@gmail.com>
11
+ License-Expression: MIT
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
14
+ Project-URL: Changelog, https://github.com/astronights/hypors/blob/main/CHANGELOG.md
15
+ Project-URL: Repository, https://github.com/astronights/hypors
16
+
17
+ # hypors
18
+
19
+ Hypothesis testing for Python, backed by the
20
+ [`hypors`](https://crates.io/crates/hypors) Rust crate.
21
+
22
+ Every statistic is computed by the Rust library — these bindings only convert
23
+ values across the boundary, so Python and Rust always agree.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install hypors
29
+ ```
30
+
31
+ ## Use
32
+
33
+ ```python
34
+ from hypors import TailType
35
+ from hypors.t import t_test
36
+
37
+ result = t_test([1.2, 2.3, 1.9, 2.5, 2.8], pop_mean=2.0, tail=TailType.Two, alpha=0.05)
38
+
39
+ print(result.test_statistic)
40
+ print(result.p_value)
41
+ print(result.reject_null)
42
+ print(result.to_dict())
43
+ ```
44
+
45
+ Any iterable of numbers works — a `list`, `tuple`, generator, `numpy` array,
46
+ `pandas.Series` or `polars.Series`. The package itself depends on none of
47
+ them:
48
+
49
+ ```python
50
+ import numpy as np
51
+ import polars as pl
52
+
53
+ t_test(np.array([1.2, 2.3, 1.9]), 2.0, TailType.Two, 0.05)
54
+ t_test(pl.Series([1.2, 2.3, 1.9]), 2.0, TailType.Two, 0.05)
55
+ ```
56
+
57
+ ## Tests available
58
+
59
+ | Module | Functions |
60
+ | --- | --- |
61
+ | `hypors.t` | `t_test`, `t_test_paired`, `t_test_ind`, `t_sample_size` |
62
+ | `hypors.z` | `z_test`, `z_test_paired`, `z_test_ind`, `z_sample_size` |
63
+ | `hypors.proportion` | `z_test`, `z_test_ind`, `prop_sample_size` |
64
+ | `hypors.anova` | `anova`, `f_sample_size` |
65
+ | `hypors.chi_square` | `independence`, `goodness_of_fit`, `variance`, `chi2_sample_size_gof`, `chi2_sample_size_ind`, `chi2_sample_size_variance` |
66
+ | `hypors.mann_whitney` | `u_test` |
67
+ | `hypors.common` | `TailType`, `TestResult` |
68
+
69
+ `TailType` and `TestResult` are also importable from the top level.
70
+
71
+ ## Results
72
+
73
+ Every test returns a `TestResult` with `test_statistic`, `p_value`,
74
+ `confidence_interval`, `null_hypothesis`, `alt_hypothesis` and `reject_null`,
75
+ plus `to_dict()` for serialising. Attributes are read-only.
76
+
77
+ Errors surface as ordinary Python exceptions: `ValueError` for empty or
78
+ insufficient data, `RuntimeError` for a computation that could not be
79
+ completed.
80
+
81
+ ## Notes
82
+
83
+ - The Mann-Whitney U p-value matches `scipy.stats.mannwhitneyu` with
84
+ `method="asymptotic"`. Its `test_statistic` is `min(U1, U2)` while the
85
+ p-value derives from `U1`, so compare p-values rather than statistics when
86
+ checking against scipy.
87
+ - Versions track the Rust crate: `hypors` on PyPI and `hypors` on crates.io
88
+ share a version number.
89
+
90
+ ## License
91
+
92
+ MIT
93
+
hypors-0.4.1/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # HypoRS: A Statistical Hypothesis Testing Library
2
+
3
+ `hypors` is a Rust library designed for performing a variety of hypothesis tests, including t-tests, z-tests, proportion tests, ANOVA, Chi-square tests, and Mann-Whitney tests. This library leverages the `statrs` crate for statistical distributions.
4
+
5
+ Rust Crate: https://crates.io/crates/hypors
6
+
7
+ PyPI Package: Work in Progress
8
+
9
+ ## Features
10
+
11
+ ### Hypothesis Tests
12
+
13
+ Hypothesis testing is available for this suite of common distributions.
14
+
15
+ - **T-Tests**: One-sample, two-sample paired, and two-sample independent t-tests.
16
+ - **Z-Tests**: One-sample, two-sample paired, and two-sample independent z-tests.
17
+ - **Proportion Tests**: One-sample and two-sample proportion tests.
18
+ - **ANOVA**: One-way ANOVA for comparing means across multiple groups.
19
+ - **Chi-Square Tests**: Chi-square test for independence and goodness-of-fit tests.
20
+ - **Mann-Whitney U Test**: Non-parametric test for comparing two independent samples.
21
+
22
+ ### Sample Size Calculation
23
+
24
+ All parametrized distributions have respective modules to calculate minimum sample size required with customizable parameters for alpha and statistical power.
25
+
26
+
27
+ ### **Additional Features**:
28
+ - Customizable tail type (left, right, and two-tailed).
29
+ - Customizable alpha value for all tests.
30
+ - Confidence interval calculations for all tests.
31
+ - p-value is generated along with each statistic.
32
+ - Null and alternate hypotheses strings are also generated.
33
+
34
+ ## Installation
35
+
36
+ To use this library in your Rust project, add the following to your `Cargo.toml`:
37
+
38
+ ```toml
39
+ [dependencies]
40
+ hypors = "0.4.0"
41
+ ```
42
+
43
+ **Note** HypoRS relies on the following dependencies, which will be automatically included:
44
+
45
+ ```
46
+ serde (version >=1.0.210)
47
+ statrs (version >=0.17.1)
48
+ ```
49
+
50
+ ## Example Usage
51
+
52
+ ### Rust
53
+
54
+ Here are some examples of running tests with Rust.
55
+
56
+ #### T - Test
57
+
58
+ ```rust
59
+ use hypors::{t::t_test, common::TailType};
60
+
61
+ let data = vec![1.2, 2.3, 1.9, 2.5, 2.8];
62
+ let population_mean = 2.0;
63
+ let tail = TailType::Two;
64
+ let alpha = 0.05;
65
+
66
+ let result = t_test(data, population_mean, tail, alpha).unwrap();
67
+ println!("Test Statistic: {}", result.test_statistic);
68
+ println!("p-value: {}", result.p_value);
69
+ println!("Confidence Interval: {}", result.confidence_interval);
70
+ println!("Null Hypothesis: {}", result.null_hypothesis);
71
+ println!("Alternate Hypothesis: {}", result.alt_hypothesis);
72
+ println!("Reject Null Hypothesis?: {}", result.reject_null);
73
+ ```
74
+
75
+ #### Chi Square Test
76
+
77
+ ```rust
78
+ use hypors::{chi_square::independence};
79
+
80
+ let observed = vec![10, 20, 30]; // Observed frequencies
81
+ let expected = vec![15, 15, 30]; // Expected frequencies
82
+
83
+ let result = independece(observed, expected).unwrap();
84
+ println!("Chi-Square Statistic: {}", result.test_statistic);
85
+ println!("p-value: {}", result.p_value);
86
+ println!("Null Hypothesis: {}", result.null_hypothesis);
87
+ println!("Alternate Hypothesis: {}", result.alt_hypothesis);
88
+ println!("Reject Null Hypothesis?: {}", result.reject_null);
89
+ ```
90
+
91
+ ### Usage with Polars
92
+
93
+ With the `polars` crate having frequent minor version updates, this library has been updated to not use Polars inherently, and relies on `Vec` types.
94
+
95
+ Any use of `polars` `Series` types should be converted before and after using the `hypors` functions.
96
+
97
+ **Polars to Vec Conversion:**
98
+ ```rust
99
+ use polars::prelude::*;
100
+ let series = Series::new("series_name", &[1, 2, 3, 4, 5]);
101
+ let vec = series.to_vec().unwrap();
102
+ ```
103
+
104
+ **Vec to Polars Conversion:**
105
+ ```rust
106
+ use polars::prelude::*;
107
+ let vec = vec![1, 2, 3, 4, 5];
108
+ let series = Series::new("series_name", vec);
109
+ ```
110
+
111
+
112
+ ### Python
113
+
114
+ Work in Progress
115
+
116
+ ## Future Plans
117
+
118
+ The next step for `hypors` is to add Python bindings to make it accessible to the Python community. This work is currently in progress. Stay tuned for updates!
119
+
120
+ ## Contributing
121
+ Contributions are always welcome! If you have suggestions for improvements, bug fixes, or new features, please feel free to open an issue or submit a pull request.
122
+
123
+ ## License
124
+ This project is licensed under the MIT License.
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.7,<2.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "hypors"
7
+ version = "0.4.1"
8
+ description = "Hypothesis testing for Python, backed by the hypors Rust crate"
9
+ readme = "README.md"
10
+ authors = [{ name = "Shubhankar Agrawal", email = "shubhankar.a31@gmail.com" }]
11
+ license = "MIT"
12
+ requires-python = ">=3.8"
13
+ keywords = ["statistics", "hypothesis", "testing", "p-value"]
14
+ classifiers = [
15
+ "Programming Language :: Rust",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: Implementation :: CPython",
18
+ "Topic :: Scientific/Engineering :: Mathematics",
19
+ ]
20
+
21
+ [project.urls]
22
+ Repository = "https://github.com/astronights/hypors"
23
+ Changelog = "https://github.com/astronights/hypors/blob/main/CHANGELOG.md"
24
+
25
+ [tool.maturin]
26
+ features = ["pyo3/extension-module"]
27
+ manifest-path = "python/Cargo.toml"