-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use transform / aggregate in two steps instead of hooks * remove constructors * update build workflow * delete old hooks * update template file * activate venv before running dont-fret * fix name * try claude's suggestion for pypi test workflow
- Loading branch information
Showing
21 changed files
with
711 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,37 @@ jobs: | |
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Configure Git | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub Actions" | ||
- name: Create test version tag | ||
run: | | ||
# Get number of commits in current branch | ||
COMMIT_COUNT=$(git rev-list --count HEAD) | ||
# Get short SHA | ||
SHA=$(git rev-parse --short HEAD) | ||
# Create a PEP 440 compliant version number | ||
VERSION="0.2.1.dev${COMMIT_COUNT}" | ||
# Create and push tag | ||
git tag -a "v${VERSION}" -m "Test release ${VERSION}" | ||
echo "Created tag v${VERSION}" | ||
- name: Install Hatch | ||
run: pip install hatch | ||
|
||
- name: Build | ||
run: hatch build | ||
|
||
- name: Publish distribution 📦 to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
repository-url: https://test.pypi.org/legacy/ | ||
repository-url: https://test.pypi.org/legacy/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from functools import wraps | ||
from typing import Callable, Iterable, Optional | ||
|
||
import polars as pl | ||
|
||
from dont_fret.expr import parse_expression | ||
from dont_fret.models import Bursts, PhotonData | ||
Check failure on line 7 in dont_fret/aggregation.py GitHub Actions / ruffRuff (F401)
|
||
from dont_fret.utils import suffice | ||
|
||
# photon aggregation hooks | ||
|
||
|
||
# Global registry of transforms | ||
aggregation_registry: dict[str, Callable] = {} | ||
|
||
|
||
def aggregate(_func=None, *, name: Optional[str] = None) -> Callable: | ||
""" | ||
Decorator to register a aggregate function. | ||
Can be used as @aggregate or @aggregate(name="custom_name") | ||
""" | ||
|
||
def decorator(func: Callable) -> Callable: | ||
agg_name = name or func.__name__ | ||
aggregation_registry[agg_name] = func | ||
|
||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
if _func is None: | ||
return decorator | ||
return decorator(_func) | ||
|
||
|
||
@aggregate | ||
def length(name="n_photons", suffix: str = "") -> list[pl.Expr]: | ||
return [pl.len().alias(suffice(name, suffix))] | ||
|
||
|
||
@aggregate | ||
def stream_length(streams: Iterable[str], suffix: str = "") -> list[pl.Expr]: | ||
"""length of each stream (number of elements)""" | ||
return [ | ||
(pl.col("stream") == stream).sum().alias(suffice(f"n_{stream}", suffix)) | ||
for stream in streams | ||
] | ||
|
||
|
||
@aggregate | ||
def stream_mean(streams: Iterable[str], column: str, suffix: str = "") -> list[pl.Expr]: | ||
return [ | ||
pl.col(column) | ||
.filter(pl.col("stream") == stream) | ||
.mean() | ||
.alias(suffice(f"{column}_{stream}", suffix)) | ||
for stream in streams | ||
] | ||
|
||
|
||
@aggregate | ||
def column_stats( | ||
column: str, stat_funcs: list[str] = ["mean", "min", "max"], suffix: str = "" | ||
) -> list[pl.Expr]: | ||
return [ | ||
getattr(pl.col(column), d)().alias(suffice(f"{column}_{d}", suffix)) for d in stat_funcs | ||
] | ||
|
||
|
||
@aggregate | ||
def parse_expr(exprs: dict[str, str], suffix: str = "") -> list[pl.Expr]: | ||
return [parse_expression(v).alias(suffice(k, suffix)) for k, v in exprs.items()] | ||
|
||
|
||
@aggregate | ||
def stream_asymmetry( | ||
lhs_streams: list[str], rhs_streams: list[str], column: str, suffix="" | ||
) -> list[pl.Expr]: | ||
value_lhs = pl.col(column).filter(pl.col("stream").is_in(lhs_streams)).mean() | ||
value_rhs = pl.col(column).filter(pl.col("stream").is_in(rhs_streams)).mean() | ||
|
||
return [(value_lhs - value_rhs).alias(suffice("asymmetry", suffix))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
from .config import CONFIG_HOME, cfg | ||
from .config import ( | ||
CONFIG_DEFAULT, | ||
CONFIG_DEFAULT_DIR, | ||
CONFIG_HOME_DIR, | ||
BurstColor, | ||
DontFRETConfig, | ||
cfg, | ||
update_config_from_yaml, | ||
) | ||
|
||
__all__ = ["cfg", "CONFIG_HOME"] | ||
__all__ = [ | ||
"CONFIG_DEFAULT", | ||
"CONFIG_DEFAULT_DIR", | ||
"CONFIG_HOME_DIR", | ||
"BurstColor", | ||
"DontFRETConfig", | ||
"cfg", | ||
"update_config_from_yaml", | ||
] |
Oops, something went wrong.