Skip to content

Commit 6f381cd

Browse files
dcherianclaude
andcommitted
refactor: extract scan and factorize functions to separate modules
- Create flox/scan.py with groupby_scan and related functions - Create flox/factorize.py with factorize_ and related functions - Move scan-related types to types.py under TYPE_CHECKING - Update imports across codebase (core, tests, benchmarks) - Maintain backward compatibility through __init__.py exports This improves code organization by separating scan operations and factorization logic from the large core.py module while preserving all existing functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f3793b9 commit 6f381cd

File tree

10 files changed

+892
-728
lines changed

10 files changed

+892
-728
lines changed

asv_bench/benchmarks/cohorts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pandas as pd
66

77
import flox
8+
from flox.factorize import _factorize_multiple
89

910
from .helpers import codes_for_resampling
1011

@@ -89,7 +90,7 @@ def setup(self, *args, **kwargs):
8990
y = np.repeat(np.arange(30), 60)
9091
by = x[np.newaxis, :] * y[:, np.newaxis]
9192

92-
self.by = flox.core._factorize_multiple((by,), expected_groups=(None,), any_by_dask=False)[0][0]
93+
self.by = _factorize_multiple((by,), expected_groups=(None,), any_by_dask=False)[0][0]
9394

9495
self.array = dask.array.ones(self.by.shape, chunks=(350, 350))
9596
self.axis = (-2, -1)
@@ -149,7 +150,7 @@ class ERA5MonthHour(ERA5Dataset, Cohorts):
149150
def setup(self, *args, **kwargs):
150151
super().__init__()
151152
by = (self.time.dt.month.values, self.time.dt.hour.values)
152-
ret = flox.core._factorize_multiple(
153+
ret = _factorize_multiple(
153154
by,
154155
(pd.Index(np.arange(1, 13)), pd.Index(np.arange(1, 25))),
155156
any_by_dask=False,

flox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from .aggregations import Aggregation, Scan # noqa
77
from .core import (
88
groupby_reduce,
9-
groupby_scan,
109
rechunk_for_blockwise,
1110
rechunk_for_cohorts,
1211
ReindexStrategy,
1312
ReindexArrayType,
1413
) # noqa
14+
from .scan import groupby_scan # noqa
1515

1616

1717
def _get_version():

0 commit comments

Comments
 (0)