corrlens 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.
- corrlens-0.1.0/.github/workflows/ci.yml +15 -0
- corrlens-0.1.0/.github/workflows/publish.yml +16 -0
- corrlens-0.1.0/.gitignore +13 -0
- corrlens-0.1.0/.readthedocs.yaml +9 -0
- corrlens-0.1.0/CHANGELOG.md +25 -0
- corrlens-0.1.0/CITATION.cff +11 -0
- corrlens-0.1.0/CONTRIBUTING.md +54 -0
- corrlens-0.1.0/LICENSE +28 -0
- corrlens-0.1.0/PKG-INFO +142 -0
- corrlens-0.1.0/README.md +113 -0
- corrlens-0.1.0/docs/api.md +164 -0
- corrlens-0.1.0/docs/changelog.md +1 -0
- corrlens-0.1.0/docs/cleaning.md +135 -0
- corrlens-0.1.0/docs/cli.md +80 -0
- corrlens-0.1.0/docs/contributing.md +1 -0
- corrlens-0.1.0/docs/faq.md +75 -0
- corrlens-0.1.0/docs/getting-started.md +166 -0
- corrlens-0.1.0/docs/images/demo_categorical_heatmap.png +0 -0
- corrlens-0.1.0/docs/images/demo_mixed_heatmap.png +0 -0
- corrlens-0.1.0/docs/images/demo_numeric_heatmap.png +0 -0
- corrlens-0.1.0/docs/index.md +74 -0
- corrlens-0.1.0/docs/large-datasets.md +88 -0
- corrlens-0.1.0/docs/outputs.md +145 -0
- corrlens-0.1.0/docs/requirements.txt +2 -0
- corrlens-0.1.0/docs/statistical-tests.md +131 -0
- corrlens-0.1.0/docs/type-detection.md +154 -0
- corrlens-0.1.0/examples/make_messy_data.py +48 -0
- corrlens-0.1.0/mkdocs.yml +26 -0
- corrlens-0.1.0/pyproject.toml +40 -0
- corrlens-0.1.0/src/corrlens/__init__.py +18 -0
- corrlens-0.1.0/src/corrlens/api.py +118 -0
- corrlens-0.1.0/src/corrlens/cli.py +81 -0
- corrlens-0.1.0/src/corrlens/convert.py +133 -0
- corrlens-0.1.0/src/corrlens/detect.py +393 -0
- corrlens-0.1.0/src/corrlens/plots.py +86 -0
- corrlens-0.1.0/src/corrlens/report.py +238 -0
- corrlens-0.1.0/src/corrlens/stats.py +337 -0
- corrlens-0.1.0/tests/test_corrlens.py +253 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
runs-on: ${{ matrix.os }}
|
|
6
|
+
strategy:
|
|
7
|
+
matrix:
|
|
8
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
9
|
+
python-version: ["3.10", "3.12", "3.13"]
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-python@v5
|
|
13
|
+
with: { python-version: "${{ matrix.python-version }}" }
|
|
14
|
+
- run: pip install -e ".[dev]"
|
|
15
|
+
- run: pytest -q
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Publishes to PyPI when you create a GitHub Release. Uses PyPI "trusted publishing":
|
|
2
|
+
# no API token needed - register this repo + workflow on pypi.org first.
|
|
3
|
+
name: Publish
|
|
4
|
+
on:
|
|
5
|
+
release: { types: [published] }
|
|
6
|
+
jobs:
|
|
7
|
+
publish:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
environment: pypi
|
|
10
|
+
permissions: { id-token: write }
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with: { python-version: "3.12" }
|
|
15
|
+
- run: pip install build && python -m build
|
|
16
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-11-22
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Semantic type detection (`detect`) with confidence scores, reasons and review flags:
|
|
11
|
+
numbers stored as text, boolean text, dates, free text, IDs, zip/postal and other codes,
|
|
12
|
+
bitmask/quality flags, years, rating scales (ordinal), constants and empty columns.
|
|
13
|
+
- Editable `Schema`: `review`, `set`, `drop`, `confirm`, `interactive_review`, JSON save/load.
|
|
14
|
+
- Automatic test selection for every pair: Pearson / Spearman / Kendall; chi-square /
|
|
15
|
+
Fisher's exact / Monte Carlo chi-square; Welch's t / Mann-Whitney U; ANOVA / Kruskal-Wallis.
|
|
16
|
+
- Effect sizes on a common 0–1 strength scale; bias-corrected Cramér's V; Theil's U.
|
|
17
|
+
- Benjamini–Hochberg and Bonferroni correction.
|
|
18
|
+
- `Report` with summary, findings table, p-value matrix, three heatmaps, HTML and CSV export.
|
|
19
|
+
- `corrlens` command-line tool (CSV, TSV, Parquet, Excel, FITS).
|
|
20
|
+
- `convert()` and `Report.clean_df`: a typed copy of the data (`float64`, `category`,
|
|
21
|
+
ordered `category`, `boolean`, `datetime64`, `string`) with a change report; never imputes.
|
|
22
|
+
- `missing=` option for `analyze()`: `pairwise` (default), `listwise` (falls back to pairwise
|
|
23
|
+
when fewer than `min_rows` complete rows remain) and `impute` (median / mode, clearly reported).
|
|
24
|
+
- CLI options `--missing` and `--clean-out`.
|
|
25
|
+
- Row sampling for large datasets; accepts astropy / polars / pyarrow tables.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use corrlens, please cite it."
|
|
3
|
+
title: "corrlens: automated, assumption-aware correlation and association analysis"
|
|
4
|
+
authors:
|
|
5
|
+
- family-names: "Ray"
|
|
6
|
+
given-names: "Debisree"
|
|
7
|
+
orcid: "https://orcid.org/0000-0001-7932-3846"
|
|
8
|
+
email: "debisreer@gmail.com"
|
|
9
|
+
version: 0.1.0
|
|
10
|
+
license: BSD-3-Clause
|
|
11
|
+
repository-code: "https://github.com/debisree/corrlens"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Contributing to corrlens
|
|
2
|
+
|
|
3
|
+
Thanks for helping! Bug reports, misdetected columns, new tests and docs fixes
|
|
4
|
+
are all welcome.
|
|
5
|
+
|
|
6
|
+
## Reporting a misdetected column
|
|
7
|
+
|
|
8
|
+
Type detection improves through real examples. Please open an issue with:
|
|
9
|
+
|
|
10
|
+
* the column name and pandas dtype;
|
|
11
|
+
* about 20 example values (anonymised is fine);
|
|
12
|
+
* what corrlens inferred (`schema.review()` row) and what it should be.
|
|
13
|
+
|
|
14
|
+
## Development setup
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/debisree/corrlens
|
|
18
|
+
cd corrlens
|
|
19
|
+
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
20
|
+
pip install -e ".[dev]"
|
|
21
|
+
pytest
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Making a change
|
|
25
|
+
|
|
26
|
+
1. Create a branch: `git checkout -b fix-zipcode-detection`.
|
|
27
|
+
2. Add or update a test in `tests/` that fails without your change.
|
|
28
|
+
3. Make the change; keep functions small and add docstrings.
|
|
29
|
+
4. Run `pytest`. All tests must pass.
|
|
30
|
+
5. Update the docs (`docs/`) and `CHANGELOG.md` if behaviour changes.
|
|
31
|
+
6. Open a pull request describing *what* and *why*.
|
|
32
|
+
|
|
33
|
+
## Statistical changes
|
|
34
|
+
|
|
35
|
+
Changes to test selection or effect sizes need a reference (paper or textbook)
|
|
36
|
+
in the pull request, and a test that checks the result against a known value
|
|
37
|
+
(for example, from R or a published example).
|
|
38
|
+
|
|
39
|
+
## Building the docs locally
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -r docs/requirements.txt
|
|
43
|
+
mkdocs serve # http://127.0.0.1:8000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Releasing (maintainers)
|
|
47
|
+
|
|
48
|
+
1. Bump `version` in `pyproject.toml`, `src/corrlens/__init__.py` and `CITATION.cff`.
|
|
49
|
+
2. Update `CHANGELOG.md`.
|
|
50
|
+
3. Tag and create a GitHub Release. The `publish.yml` workflow uploads to PyPI.
|
|
51
|
+
|
|
52
|
+
## Code of conduct
|
|
53
|
+
|
|
54
|
+
Be kind and constructive. Harassment of any kind is not tolerated.
|
corrlens-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Debisree Ray
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
corrlens-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: corrlens
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Automated, assumption-aware correlation and association analysis for mixed-type data
|
|
5
|
+
Project-URL: Homepage, https://github.com/debisree/corrlens
|
|
6
|
+
Project-URL: Issues, https://github.com/debisree/corrlens/issues
|
|
7
|
+
Author-email: Debisree Ray <debisreer@gmail.com>
|
|
8
|
+
License-Expression: BSD-3-Clause
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: chi-square,correlation,cramers-v,data-types,eda,heatmap,statistics
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: matplotlib>=3.7
|
|
17
|
+
Requires-Dist: numpy>=1.24
|
|
18
|
+
Requires-Dist: pandas>=2.0
|
|
19
|
+
Requires-Dist: scipy>=1.15
|
|
20
|
+
Provides-Extra: astro
|
|
21
|
+
Requires-Dist: astropy>=6.0; extra == 'astro'
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
25
|
+
Requires-Dist: twine; extra == 'dev'
|
|
26
|
+
Provides-Extra: parquet
|
|
27
|
+
Requires-Dist: pyarrow>=14; extra == 'parquet'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# corrlens
|
|
31
|
+
|
|
32
|
+
**Automated, assumption-aware correlation and association analysis for mixed-type data.**
|
|
33
|
+
|
|
34
|
+
Point it at any table. corrlens works out what each column *means* (not just how
|
|
35
|
+
it is stored), asks you to confirm the doubtful ones, picks the right test for
|
|
36
|
+
every pair of variables, corrects for multiple testing, and gives you heatmaps,
|
|
37
|
+
a p-value matrix, a findings table and a plain-language summary.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import corrlens
|
|
41
|
+
|
|
42
|
+
schema = corrlens.detect(df) # infer semantic types
|
|
43
|
+
schema.review() # flagged columns first, with reasons
|
|
44
|
+
schema.set("store_zip", "categorical").drop("customer_id").confirm()
|
|
45
|
+
|
|
46
|
+
clean_df = corrlens.convert(df, schema) # your data with proper dtypes (copy)
|
|
47
|
+
|
|
48
|
+
report = corrlens.analyze(df, schema) # missing="pairwise" | "listwise" | "impute"
|
|
49
|
+
print(report.summary()) # key findings in plain language
|
|
50
|
+
report.findings # one row per pair: test, effect, p, adjusted p, warnings
|
|
51
|
+
report.pvalue_matrix() # adjusted p-values
|
|
52
|
+
report.plot() # heatmaps (numeric / categorical / mixed)
|
|
53
|
+
report.to_html("report.html") # self-contained report
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Command line:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
corrlens data.csv --out report.html --csv findings.csv
|
|
60
|
+
corrlens data.csv --save-schema schema.json # detect, edit the JSON, then:
|
|
61
|
+
corrlens data.csv --schema schema.json
|
|
62
|
+
corrlens catalogue.fits --max-rows 1000000 # needs: pip install corrlens[astro]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Why not just `df.corr()`?
|
|
66
|
+
|
|
67
|
+
| | `df.corr()` | corrlens |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| Numbers stored as text (`"$1,200"`, `"12%"`) | dropped | parsed |
|
|
70
|
+
| Zip codes, IDs, rating scales stored as int | correlated as quantities | detected, flagged for review |
|
|
71
|
+
| Gives back a correctly typed DataFrame | – | `convert()` / `report.clean_df` |
|
|
72
|
+
| Missing values | silently pairwise | pairwise, listwise (with fallback) or impute — always reported |
|
|
73
|
+
| Categorical variables | dropped | chi-square / Fisher, Cramér's V, Theil's U |
|
|
74
|
+
| Categorical ↔ numeric | – | t-test / Mann-Whitney / ANOVA / Kruskal-Wallis |
|
|
75
|
+
| p-values | – | per pair, with FDR or Bonferroni correction |
|
|
76
|
+
| Test choice | you decide | chosen from normality, outliers, sample size, cell counts — and explained |
|
|
77
|
+
| Large-n honesty | – | effect sizes lead; "significant but negligible" called out |
|
|
78
|
+
|
|
79
|
+
## Semantic types
|
|
80
|
+
|
|
81
|
+
`numeric`, `ordinal`, `binary`, `categorical` are analysed; `identifier`, `datetime`,
|
|
82
|
+
`text`, `constant`, `empty` are excluded. Every decision has a confidence and a
|
|
83
|
+
reason. Reinterpretations (an int column treated as categorical, text parsed as
|
|
84
|
+
numbers) and low-confidence calls are flagged until you `confirm()` or override them.
|
|
85
|
+
|
|
86
|
+
## Test selection
|
|
87
|
+
|
|
88
|
+
| Pair | Primary test | Effect size |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| numeric–numeric | Pearson if both roughly normal and few outliers, else Spearman; Kendall if n < 30 | r / ρ / τ |
|
|
91
|
+
| ordinal involved | Spearman (Kendall if n < 30) | ρ / τ |
|
|
92
|
+
| categorical–categorical | chi-square; Fisher exact for sparse 2×2; Monte Carlo p for sparse larger tables | bias-corrected Cramér's V (+ Theil's U) |
|
|
93
|
+
| binary–numeric | Welch's t-test (normal or large groups) else Mann-Whitney U | point-biserial / rank-biserial r |
|
|
94
|
+
| k-level–numeric | ANOVA (normal, equal variance) else Kruskal-Wallis | η / ε |
|
|
95
|
+
|
|
96
|
+
All effect sizes sit on a 0–1 strength scale (negligible < .1 < weak < .3 < moderate < .5 < strong < .7 < very strong).
|
|
97
|
+
|
|
98
|
+
## Large datasets
|
|
99
|
+
|
|
100
|
+
`analyze` samples to `max_rows=500_000` by default (set `None` for all rows).
|
|
101
|
+
At that size every p-value is tiny, so the effect size is what matters. Anything
|
|
102
|
+
with `to_pandas()` (astropy `Table`, polars, pyarrow) is accepted.
|
|
103
|
+
Benchmark: 3 M rows × 20 columns — detection 12 s, analysis 40 s (sampled) / 4.5 min (full), 2.3 GB peak.
|
|
104
|
+
|
|
105
|
+
## Documentation
|
|
106
|
+
|
|
107
|
+
Full documentation is in [`docs/`](docs/index.md) (published with Read the Docs via `mkdocs.yml`):
|
|
108
|
+
|
|
109
|
+
- [Getting started](docs/getting-started.md) — full walkthrough on a messy dataset
|
|
110
|
+
- [Type detection](docs/type-detection.md) — every rule, and how to review and override
|
|
111
|
+
- [Statistical tests](docs/statistical-tests.md) — which test, when, and why
|
|
112
|
+
- [Cleaned data & missing values](docs/cleaning.md) — typed DataFrame back, missing-value strategies
|
|
113
|
+
- [Outputs](docs/outputs.md) — summary, findings table, p-values, heatmaps, HTML
|
|
114
|
+
- [Command line](docs/cli.md) · [Large datasets & astronomy](docs/large-datasets.md)
|
|
115
|
+
- [API reference](docs/api.md) · [FAQ & limitations](docs/faq.md)
|
|
116
|
+
|
|
117
|
+
Preview locally: `pip install -r docs/requirements.txt && mkdocs serve`
|
|
118
|
+
|
|
119
|
+
## Install (development)
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pip install -e ".[dev]"
|
|
123
|
+
pytest
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Limitations
|
|
127
|
+
|
|
128
|
+
Associations are not causal. Type detection is heuristic — review flagged columns.
|
|
129
|
+
Pairwise tests do not control for confounders (partial correlation is on the roadmap).
|
|
130
|
+
|
|
131
|
+
## Author
|
|
132
|
+
|
|
133
|
+
**Debisree Ray, Ph.D.**
|
|
134
|
+
[GitHub](https://github.com/debisree) · [LinkedIn](https://www.linkedin.com/in/debisree-ray-ph-d-82241355/) · [ORCID 0000-0001-7932-3846](https://orcid.org/0000-0001-7932-3846)
|
|
135
|
+
|
|
136
|
+
## Citation
|
|
137
|
+
|
|
138
|
+
If you use corrlens in your research, please cite it. GitHub's **"Cite this repository"** button (from `CITATION.cff`) gives the reference in APA and BibTeX.
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
BSD-3-Clause © 2026 Debisree Ray
|
corrlens-0.1.0/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# corrlens
|
|
2
|
+
|
|
3
|
+
**Automated, assumption-aware correlation and association analysis for mixed-type data.**
|
|
4
|
+
|
|
5
|
+
Point it at any table. corrlens works out what each column *means* (not just how
|
|
6
|
+
it is stored), asks you to confirm the doubtful ones, picks the right test for
|
|
7
|
+
every pair of variables, corrects for multiple testing, and gives you heatmaps,
|
|
8
|
+
a p-value matrix, a findings table and a plain-language summary.
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
import corrlens
|
|
12
|
+
|
|
13
|
+
schema = corrlens.detect(df) # infer semantic types
|
|
14
|
+
schema.review() # flagged columns first, with reasons
|
|
15
|
+
schema.set("store_zip", "categorical").drop("customer_id").confirm()
|
|
16
|
+
|
|
17
|
+
clean_df = corrlens.convert(df, schema) # your data with proper dtypes (copy)
|
|
18
|
+
|
|
19
|
+
report = corrlens.analyze(df, schema) # missing="pairwise" | "listwise" | "impute"
|
|
20
|
+
print(report.summary()) # key findings in plain language
|
|
21
|
+
report.findings # one row per pair: test, effect, p, adjusted p, warnings
|
|
22
|
+
report.pvalue_matrix() # adjusted p-values
|
|
23
|
+
report.plot() # heatmaps (numeric / categorical / mixed)
|
|
24
|
+
report.to_html("report.html") # self-contained report
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Command line:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
corrlens data.csv --out report.html --csv findings.csv
|
|
31
|
+
corrlens data.csv --save-schema schema.json # detect, edit the JSON, then:
|
|
32
|
+
corrlens data.csv --schema schema.json
|
|
33
|
+
corrlens catalogue.fits --max-rows 1000000 # needs: pip install corrlens[astro]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Why not just `df.corr()`?
|
|
37
|
+
|
|
38
|
+
| | `df.corr()` | corrlens |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| Numbers stored as text (`"$1,200"`, `"12%"`) | dropped | parsed |
|
|
41
|
+
| Zip codes, IDs, rating scales stored as int | correlated as quantities | detected, flagged for review |
|
|
42
|
+
| Gives back a correctly typed DataFrame | – | `convert()` / `report.clean_df` |
|
|
43
|
+
| Missing values | silently pairwise | pairwise, listwise (with fallback) or impute — always reported |
|
|
44
|
+
| Categorical variables | dropped | chi-square / Fisher, Cramér's V, Theil's U |
|
|
45
|
+
| Categorical ↔ numeric | – | t-test / Mann-Whitney / ANOVA / Kruskal-Wallis |
|
|
46
|
+
| p-values | – | per pair, with FDR or Bonferroni correction |
|
|
47
|
+
| Test choice | you decide | chosen from normality, outliers, sample size, cell counts — and explained |
|
|
48
|
+
| Large-n honesty | – | effect sizes lead; "significant but negligible" called out |
|
|
49
|
+
|
|
50
|
+
## Semantic types
|
|
51
|
+
|
|
52
|
+
`numeric`, `ordinal`, `binary`, `categorical` are analysed; `identifier`, `datetime`,
|
|
53
|
+
`text`, `constant`, `empty` are excluded. Every decision has a confidence and a
|
|
54
|
+
reason. Reinterpretations (an int column treated as categorical, text parsed as
|
|
55
|
+
numbers) and low-confidence calls are flagged until you `confirm()` or override them.
|
|
56
|
+
|
|
57
|
+
## Test selection
|
|
58
|
+
|
|
59
|
+
| Pair | Primary test | Effect size |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| numeric–numeric | Pearson if both roughly normal and few outliers, else Spearman; Kendall if n < 30 | r / ρ / τ |
|
|
62
|
+
| ordinal involved | Spearman (Kendall if n < 30) | ρ / τ |
|
|
63
|
+
| categorical–categorical | chi-square; Fisher exact for sparse 2×2; Monte Carlo p for sparse larger tables | bias-corrected Cramér's V (+ Theil's U) |
|
|
64
|
+
| binary–numeric | Welch's t-test (normal or large groups) else Mann-Whitney U | point-biserial / rank-biserial r |
|
|
65
|
+
| k-level–numeric | ANOVA (normal, equal variance) else Kruskal-Wallis | η / ε |
|
|
66
|
+
|
|
67
|
+
All effect sizes sit on a 0–1 strength scale (negligible < .1 < weak < .3 < moderate < .5 < strong < .7 < very strong).
|
|
68
|
+
|
|
69
|
+
## Large datasets
|
|
70
|
+
|
|
71
|
+
`analyze` samples to `max_rows=500_000` by default (set `None` for all rows).
|
|
72
|
+
At that size every p-value is tiny, so the effect size is what matters. Anything
|
|
73
|
+
with `to_pandas()` (astropy `Table`, polars, pyarrow) is accepted.
|
|
74
|
+
Benchmark: 3 M rows × 20 columns — detection 12 s, analysis 40 s (sampled) / 4.5 min (full), 2.3 GB peak.
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
Full documentation is in [`docs/`](docs/index.md) (published with Read the Docs via `mkdocs.yml`):
|
|
79
|
+
|
|
80
|
+
- [Getting started](docs/getting-started.md) — full walkthrough on a messy dataset
|
|
81
|
+
- [Type detection](docs/type-detection.md) — every rule, and how to review and override
|
|
82
|
+
- [Statistical tests](docs/statistical-tests.md) — which test, when, and why
|
|
83
|
+
- [Cleaned data & missing values](docs/cleaning.md) — typed DataFrame back, missing-value strategies
|
|
84
|
+
- [Outputs](docs/outputs.md) — summary, findings table, p-values, heatmaps, HTML
|
|
85
|
+
- [Command line](docs/cli.md) · [Large datasets & astronomy](docs/large-datasets.md)
|
|
86
|
+
- [API reference](docs/api.md) · [FAQ & limitations](docs/faq.md)
|
|
87
|
+
|
|
88
|
+
Preview locally: `pip install -r docs/requirements.txt && mkdocs serve`
|
|
89
|
+
|
|
90
|
+
## Install (development)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e ".[dev]"
|
|
94
|
+
pytest
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Limitations
|
|
98
|
+
|
|
99
|
+
Associations are not causal. Type detection is heuristic — review flagged columns.
|
|
100
|
+
Pairwise tests do not control for confounders (partial correlation is on the roadmap).
|
|
101
|
+
|
|
102
|
+
## Author
|
|
103
|
+
|
|
104
|
+
**Debisree Ray, Ph.D.**
|
|
105
|
+
[GitHub](https://github.com/debisree) · [LinkedIn](https://www.linkedin.com/in/debisree-ray-ph-d-82241355/) · [ORCID 0000-0001-7932-3846](https://orcid.org/0000-0001-7932-3846)
|
|
106
|
+
|
|
107
|
+
## Citation
|
|
108
|
+
|
|
109
|
+
If you use corrlens in your research, please cite it. GitHub's **"Cite this repository"** button (from `CITATION.cff`) gives the reference in APA and BibTeX.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
BSD-3-Clause © 2026 Debisree Ray
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
```python
|
|
4
|
+
import corrlens
|
|
5
|
+
corrlens.detect # -> Schema
|
|
6
|
+
corrlens.convert # -> DataFrame (typed copy)
|
|
7
|
+
corrlens.analyze # -> Report
|
|
8
|
+
corrlens.Schema
|
|
9
|
+
corrlens.ColumnInfo
|
|
10
|
+
corrlens.Report
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## `corrlens.detect(df)`
|
|
16
|
+
|
|
17
|
+
Infer a semantic type for every column.
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Description |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `df` | DataFrame, or any object with `to_pandas()` | the data |
|
|
22
|
+
|
|
23
|
+
**Returns** a [`Schema`](#schema).
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## `corrlens.convert(df, schema=None, *, drop_excluded=False, report=False)`
|
|
28
|
+
|
|
29
|
+
Return a copy of `df` with each column converted to the pandas dtype for its
|
|
30
|
+
semantic type (see the [conversion table](cleaning.md#get-your-data-back-with-the-right-dtypes)).
|
|
31
|
+
Missing values are kept; nothing is imputed.
|
|
32
|
+
|
|
33
|
+
| Parameter | Default | Description |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `df` | — | DataFrame, or any object with `to_pandas()` |
|
|
36
|
+
| `schema` | `None` | reviewed `Schema`; detected automatically if omitted |
|
|
37
|
+
| `drop_excluded` | `False` | drop identifier, datetime, text, constant and empty columns |
|
|
38
|
+
| `report` | `False` | also return a DataFrame of changes (`column`, `from_dtype`, `to_dtype`, `semantic_type`, `values_made_missing`) |
|
|
39
|
+
|
|
40
|
+
**Returns** a DataFrame, or `(DataFrame, changes)` when `report=True`.
|
|
41
|
+
**Warns** (`UserWarning`) if any value could not be converted and became missing.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## `corrlens.analyze(data, schema=None, *, ...)`
|
|
46
|
+
|
|
47
|
+
Detect types (or use `schema`), run all pairwise tests, and return a [`Report`](#report).
|
|
48
|
+
|
|
49
|
+
| Parameter | Default | Description |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `data` | — | DataFrame, or any object with `to_pandas()` (astropy Table, polars, pyarrow) |
|
|
52
|
+
| `schema` | `None` | a reviewed `Schema`. If `None`, types are detected and a `UserWarning` lists unconfirmed flagged columns |
|
|
53
|
+
| `missing` | `"pairwise"` | `"pairwise"`, `"listwise"` or `"impute"` ([details](cleaning.md#missing-values-in-the-tests)) |
|
|
54
|
+
| `min_rows` | `30` | for `listwise`: if fewer complete rows remain, fall back to `pairwise` |
|
|
55
|
+
| `alpha` | `0.05` | significance level for adjusted p-values |
|
|
56
|
+
| `correction` | `"fdr_bh"` | `"fdr_bh"`, `"bonferroni"` or `"none"` |
|
|
57
|
+
| `max_rows` | `500_000` | randomly sample down to this many rows before testing; `None` = all |
|
|
58
|
+
| `random_state` | `0` | seed for sampling |
|
|
59
|
+
| `max_levels` | `50` | categorical columns keep at most this many levels (the rest become `"__other__"`) |
|
|
60
|
+
| `min_level_count` | `5` | levels with fewer rows are merged into `"__other__"` |
|
|
61
|
+
| `interactive` | `False` | prompt for each flagged column (only when `schema` is `None`) |
|
|
62
|
+
| `columns` | `None` | analyse only these columns |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Schema
|
|
67
|
+
|
|
68
|
+
Editable result of `detect()`. Holds a `ColumnInfo` for each column in
|
|
69
|
+
`schema.columns` (a dict).
|
|
70
|
+
|
|
71
|
+
| Member | Description |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `schema[col]` | the `ColumnInfo` for `col` |
|
|
74
|
+
| `review()` | DataFrame of all columns, flagged and least-confident first |
|
|
75
|
+
| `to_frame()` | the same table in column order |
|
|
76
|
+
| `flagged` | list of flagged columns not yet confirmed |
|
|
77
|
+
| `analyzable()` | list of columns that will be tested |
|
|
78
|
+
| `set(col, semantic, levels=None)` | override a type (marks it confirmed); `levels` gives the order for ordinal text. Raises `ValueError` for unknown types |
|
|
79
|
+
| `drop(*cols)` | exclude columns (sets them to `identifier`, confirmed) |
|
|
80
|
+
| `confirm(*cols)` | accept the inferred type; with no arguments, accepts every flagged column |
|
|
81
|
+
| `interactive_review(input_fn=input, print_fn=print)` | prompt for each flagged column |
|
|
82
|
+
| `to_json(path=None)` | serialise to JSON; writes to `path` if given; returns the text |
|
|
83
|
+
| `Schema.from_json(path_or_text)` | load from a file path or a JSON string |
|
|
84
|
+
|
|
85
|
+
`set`, `drop`, `confirm` and `interactive_review` return the schema, so they can
|
|
86
|
+
be chained.
|
|
87
|
+
|
|
88
|
+
Valid semantic types: `numeric`, `ordinal`, `binary`, `categorical`,
|
|
89
|
+
`identifier`, `datetime`, `text`, `constant`, `empty`.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## ColumnInfo
|
|
94
|
+
|
|
95
|
+
| Field | Description |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `name` | column name |
|
|
98
|
+
| `dtype` | pandas dtype as a string |
|
|
99
|
+
| `semantic` | inferred or user-set type |
|
|
100
|
+
| `confidence` | 0–1 |
|
|
101
|
+
| `reason` | explanation |
|
|
102
|
+
| `n_unique` | distinct non-missing values |
|
|
103
|
+
| `missing_frac` | fraction missing (empty strings count as missing) |
|
|
104
|
+
| `parse` | `"numeric_text"` if text must be cleaned into numbers |
|
|
105
|
+
| `needs_review` | flagged by the detector |
|
|
106
|
+
| `confirmed` | accepted or overridden by the user |
|
|
107
|
+
| `levels` | explicit order for ordinal columns |
|
|
108
|
+
| `analyzable` | property: whether the column will be tested |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Report
|
|
113
|
+
|
|
114
|
+
| Member | Description |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `summary(top=10)` | plain-language summary string; also `repr(report)` |
|
|
117
|
+
| `findings` | DataFrame, one row per tested pair (see [Outputs](outputs.md#findings-table)) |
|
|
118
|
+
| `significant` | `findings` filtered to significant rows |
|
|
119
|
+
| `pvalue_matrix(adjusted=True)` | square DataFrame of p-values |
|
|
120
|
+
| `matrices()` | `{"numeric" / "categorical" / "mixed": (effect DataFrame, p_adj DataFrame)}` |
|
|
121
|
+
| `plot(which=None)` | dict of matplotlib Figures, or one Figure if `which` is given |
|
|
122
|
+
| `save_plots(prefix="corrlens")` | write PNGs; returns the paths |
|
|
123
|
+
| `to_html(path=None)` | self-contained HTML report; returns the HTML string |
|
|
124
|
+
| `to_csv(path)` | write the findings table |
|
|
125
|
+
| `clean_df` | typed copy of the full input (cached) |
|
|
126
|
+
| `missing`, `missing_requested` | missing-value strategy used / requested |
|
|
127
|
+
| `results` | list of `PairResult` |
|
|
128
|
+
| `schema`, `alpha`, `correction`, `n_rows`, `n_rows_used`, `notes` | settings and metadata |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## PairResult
|
|
133
|
+
|
|
134
|
+
The full result for one pair (`report.results[i]`).
|
|
135
|
+
|
|
136
|
+
| Field | Description |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `var1`, `var2`, `type1`, `type2` | the pair and its types |
|
|
139
|
+
| `test` | primary test |
|
|
140
|
+
| `statistic`, `p_value`, `p_adj`, `significant` | test outcome |
|
|
141
|
+
| `effect_measure`, `effect`, `strength`, `strength_label` | effect size, its 0–1 strength and label |
|
|
142
|
+
| `n` | complete-case rows |
|
|
143
|
+
| `secondary` | dict of extra statistics (`pearson_r`, `spearman_rho`, `kendall_tau`, `chi2`, `dof`, `cramers_v`, `theils_u_1given2`, `theils_u_2given1`, `cohens_d`, `eta_squared`, `epsilon_squared`, `odds_ratio`, …, depending on the test) |
|
|
144
|
+
| `warnings` | list of strings |
|
|
145
|
+
| `reason` | why this test was chosen |
|
|
146
|
+
| `interpretation` | sentence |
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Lower-level helpers
|
|
151
|
+
|
|
152
|
+
These are importable from their modules for advanced use:
|
|
153
|
+
|
|
154
|
+
| Function | Description |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `corrlens.detect.detect_column(series, name=None)` | detect one column → `ColumnInfo` |
|
|
157
|
+
| `corrlens.detect.clean_numeric_text(series)` | `"$1,200"`, `"12%"`, `"(45)"` → floats |
|
|
158
|
+
| `corrlens.detect.prepare(df, schema, max_levels=50, min_level_count=5)` | apply a schema → `(prepared_df, notes)` |
|
|
159
|
+
| `corrlens.api.handle_missing(data, types, missing="pairwise", min_rows=30)` | apply a missing-value strategy to prepared data → `(data, notes, strategy_used)` |
|
|
160
|
+
| `corrlens.stats.run_all(data, types, alpha, correction)` | run tests on prepared data → `list[PairResult]` |
|
|
161
|
+
| `corrlens.stats.adjust_pvalues(p, method="fdr_bh")` | BH / Bonferroni correction |
|
|
162
|
+
| `corrlens.stats.cramers_v_corrected(table, chi2)` | bias-corrected Cramér's V |
|
|
163
|
+
| `corrlens.stats.theils_u(x, y)` | uncertainty coefficient U(x \| y) |
|
|
164
|
+
| `corrlens.plots.heatmap(values, padj, title, measure, signed, alpha=0.05, triangle=True, ax=None)` | draw one heatmap |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--8<-- "CHANGELOG.md"
|