Skip to content

Commit 96adbaf

Browse files
version and tox update (#31)
1 parent c2ffde1 commit 96adbaf

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Alphalens depends on:
7171
- [seaborn](https://github.com/mwaskom/seaborn)
7272
- [statsmodels](https://github.com/statsmodels/statsmodels)
7373

74+
> Note that Numpy>=2.0 requires pandas>=2.2.2. If you are using an older version of pandas, you may need to upgrade
75+
> accordingly, otherwise you may encounter compatibility issues.
76+
7477
# Usage
7578

7679
A good way to get started is to run the examples in a [Jupyter notebook](https://jupyter.org/).

pyproject.toml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ classifiers = [
3030
]
3131

3232
dependencies = [
33+
# following pandas
34+
"numpy>=1.23.5; python_version<'3.12'",
35+
"numpy>=1.26.0; python_version>='3.12'",
36+
"pandas >=1.3.0,<3.0",
3337
"matplotlib >=1.4.0",
34-
"numpy >=1.9.1",
35-
"pandas >=1.2.0,<3.0",
3638
"scipy >=0.14.0",
3739
"seaborn >=0.6.0",
3840
"statsmodels >=0.6.1",
@@ -49,8 +51,6 @@ documentation = 'https://alphalens.ml4trading.io'
4951
requires = [
5052
'setuptools>=54.0.0',
5153
"setuptools_scm[toml]>=6.2",
52-
'wheel>=0.31.0',
53-
'oldest-supported-numpy; python_version>="3.8"',
5454
]
5555

5656
build-backend = 'setuptools.build_meta'
@@ -98,12 +98,12 @@ version_scheme = 'guess-next-dev'
9898
local_scheme = 'dirty-tag'
9999

100100

101-
[tool.pytest]
101+
[tool.pytest.ini_options]
102+
pythonpath = ['src']
102103
minversion = "6.0"
103104
testpaths = 'tests'
104105
addopts = '-v'
105106

106-
107107
[tool.cibuildwheel]
108108
test-extras = "test"
109109
test-command = "pytest -n 2 {package}/tests"
@@ -122,18 +122,29 @@ skip = "*musllinux*"
122122

123123
[tool.black]
124124
line-length = 88
125-
target-version = ['py38', 'py39', 'py310']
125+
target-version = ['py39', 'py310', 'py311', 'py312']
126126
include = '\.pyi?$'
127127
extend-exclude = '''
128128
\(
129129
docs/source/conf.py
130130
\)
131131
'''
132132

133+
133134
[tool.tox]
134135
legacy_tox_ini = """
135136
[tox]
136-
envlist = py39-pandas12, py{39,310,311}-pandas{13,14,15}, py{39,310,311,312}-pandas{15,20,21,22}
137+
138+
envlist =
139+
py39-pandas{13,14,15}-numpy1
140+
py310-pandas{13,14,15,20,21,22}-numpy1
141+
py311-pandas{13,14,15,20,21,22}-numpy1
142+
py312-pandas{13,14,15,20,21,22}-numpy1
143+
py39-pandas222-numpy2
144+
py310-pandas222-numpy2
145+
py311-pandas222-numpy2
146+
py312-pandas222-numpy2
147+
137148
isolated_build = True
138149
skip_missing_interpreters = True
139150
minversion = 3.23.0
@@ -153,13 +164,16 @@ setenv =
153164
changedir = tmp
154165
extras = test
155166
deps =
156-
pandas12: pandas>=1.2.0,<1.3
157167
pandas13: pandas>=1.3.0,<1.4
158168
pandas14: pandas>=1.4.0,<1.5
159169
pandas15: pandas>=1.5.0,<1.6
160170
pandas20: pandas>=2.0,<2.1
161171
pandas21: pandas>=2.1,<2.2
162172
pandas22: pandas>=2.2,<2.3
173+
pandas222: pandas>=2.2.2,<2.3
174+
numpy1: numpy>=1.23.5,<2.0
175+
numpy2: numpy>=2.0,<2.1
176+
163177
164178
commands =
165179
pytest -n 2 --cov={toxinidir}/src --cov-report term --cov-report=xml --cov-report=html:htmlcov {toxinidir}/tests

src/alphalens/performance.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def src_ic(group):
7070
if by_group:
7171
grouper.append("group")
7272

73-
ic = factor_data.groupby(grouper).apply(src_ic)
73+
ic = factor_data.groupby(grouper, observed=True).apply(src_ic)
7474
if by_group:
7575
return ic
7676
else:
@@ -195,9 +195,9 @@ def to_weights(group, _demeaned, _equal_weight):
195195
if group_adjust:
196196
grouper.append("group")
197197

198-
weights = factor_data.groupby(grouper, group_keys=False)["factor"].apply(
199-
to_weights, demeaned, equal_weight
200-
)
198+
weights = factor_data.groupby(grouper, group_keys=False, observed=True)[
199+
"factor"
200+
].apply(to_weights, demeaned, equal_weight)
201201

202202
if group_adjust:
203203
weights = weights.groupby(level="date", group_keys=False).apply(
@@ -507,7 +507,7 @@ def mean_return_by_quantile(
507507
if by_group:
508508
grouper.append("group")
509509

510-
group_stats = factor_data.groupby(grouper)[
510+
group_stats = factor_data.groupby(grouper, observed=True)[
511511
utils.get_forward_returns_columns(factor_data.columns)
512512
].agg(["mean", "std", "count"])
513513

@@ -847,7 +847,7 @@ def average_cumulative_return(q_fact, demean_by):
847847
#
848848
returns_bygroup = []
849849

850-
for group, g_data in factor_data.groupby("group"):
850+
for group, g_data in factor_data.groupby("group", observed=True):
851851
g_fq = g_data["factor_quantile"]
852852
if group_adjust:
853853
demean_by = g_fq # demeans at group level
@@ -878,7 +878,7 @@ def average_cumulative_return(q_fact, demean_by):
878878
#
879879
if group_adjust:
880880
all_returns = []
881-
for group, g_data in factor_data.groupby("group"):
881+
for group, g_data in factor_data.groupby("group", observed=True):
882882
g_fq = g_data["factor_quantile"]
883883
avgcumret = g_fq.groupby(g_fq).apply(
884884
cumulative_return_around_event, g_fq

0 commit comments

Comments
 (0)