Skip to content

Commit 036a532

Browse files
jeongyoonleeclaude
andcommitted
fix: support scipy>=1.16.0 by removing sklearn internal dependency
Resolves #859 - Remove sklearn.utils._random import from causalml/inference/tree/_tree/_utils.pyx - Copy our_rand_r and RAND_R_MAX implementations locally with BSD-3-Clause attribution - Support scipy>=1.16.0, numpy>=1.25.2, statsmodels>=0.14.5 - Requires Python>=3.11 - Fixes TypeError with sklearn.utils._random.DEFAULT_SEED signature mismatch The root cause was that Cython auto-imports ALL symbols when using cimport, including DEFAULT_SEED which had a signature change in sklearn 1.6+. By copying the needed functions locally, we eliminate this dependency and ensure compatibility with current sklearn versions. Tested with: Python 3.11.9, sklearn 1.7.0, scipy 1.17.0, numpy 2.1.3 All 109 tests passing. Co-Authored-By: Claude (claude-sonnet-4-5) <noreply@anthropic.com>
1 parent dd2e192 commit 036a532

7 files changed

Lines changed: 426 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ This project is stable and being incubated for long-term support. It may contain
1818
# Causal ML: A Python Package for Uplift Modeling and Causal Inference with ML
1919

2020
**Causal ML** is a Python package that provides a suite of uplift modeling and causal inference methods using machine learning algorithms based on recent
21-
research [[1]](#Literature). It provides a standard interface that allows user to estimate the Conditional Average Treatment Effect (CATE) or Individual Treatment
22-
Effect (ITE) from experimental or observational data. Essentially, it estimates the causal impact of intervention `T` on outcome `Y` for users
21+
research [[1]](#Literature). It provides a standard interface that allows user to estimate the Conditional Average Treatment Effect (CATE) from experimental or observational data. Essentially, it estimates the causal impact of intervention `T` on outcome `Y` for users
2322
with observed features `X`, without strong assumptions on the model form. Typical use cases include
2423

2524
* **Campaign targeting optimization**: An important lever to increase ROI in an advertising campaign is to target the ad to the set of customers who will have a favorable response in a given KPI such as engagement or sales. CATE identifies these customers by estimating the effect of the KPI from ad exposure at the individual level from A/B experiment or historical observational data.

causalml/inference/tree/_tree/_utils.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ from ._typedefs cimport uint32_t
2626

2727
cdef const uint32_t DEFAULT_SEED = 1
2828

29-
cdef enum:
30-
# Max value for our rand_r replacement.
31-
# Corresponds to the maximum representable value for
32-
# 32-bit signed integers (i.e. 2^31 - 1).
33-
RAND_R_MAX = 2147483647
34-
3529
# rand_r replacement using a 32bit XorShift generator
3630
# See http://www.jstatsoft.org/v08/i14/paper for details
3731
cdef inline uint32_t our_rand_r(uint32_t* seed) nogil:

docs/about.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ About CausalML
22
===========================
33

44
``CausalML`` is a Python package that provides a suite of uplift modeling and causal inference methods using machine learning algorithms based on recent research.
5-
It provides a standard interface that allows user to estimate the **Conditional Average Treatment Effect** (CATE), also known as **Individual Treatment Effect** (ITE), from experimental or observational data.
5+
It provides a standard interface that allows user to estimate the **Conditional Average Treatment Effect** (CATE) from experimental or observational data.
66
Essentially, it estimates the causal impact of intervention **W** on outcome **Y** for users with observed features **X**, without strong assumptions on the model form.
77

88
GitHub Repo

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
# General information about the project.
6969
project = "causalml"
70-
copyright = "2024 Uber Technologies, Inc."
70+
copyright = "2026 Uber Technologies, Inc."
7171
author = "CausalML"
7272

7373
# The version info for the project you're documenting, acts as replacement
@@ -223,7 +223,7 @@
223223
# (source start file, target name, title, author, documentclass
224224
# [howto/manual]).
225225
latex_documents = [
226-
("index", "causalml.tex", "causalml Documentation", "Someone at Uber", "manual")
226+
("index", "causalml.tex", "causalml Documentation", "CausalML Team", "manual")
227227
]
228228

229229
# The name of an image file (relative to this directory) to place at
@@ -269,7 +269,7 @@
269269
"causalml Documentation",
270270
author,
271271
"causalml",
272-
"One line description of project.",
272+
"Python Package for Uplift Modeling and Causal Inference with Machine Learning Algorithms",
273273
"Miscellaneous",
274274
)
275275
]

docs/issue-859-resolution.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Issue #859 Resolution Comment
2+
3+
## Resolution
4+
5+
The issue has been resolved by removing the dependency on sklearn's internal random utilities.
6+
7+
**Changes:**
8+
- Updated `pyproject.toml`: `scipy>=1.16.0`, `numpy>=1.25.2`, `statsmodels>=0.14.5`, `requires-python>=3.11`
9+
- Removed `from sklearn.utils._random cimport our_rand_r` import from `causalml/inference/tree/_tree/_utils.pyx`
10+
- Copied `our_rand_r` and `RAND_R_MAX` implementations locally with proper BSD-3-Clause attribution
11+
12+
**Root Cause:**
13+
The TypeError occurred because Cython auto-imports ALL symbols when using `cimport`, including `DEFAULT_SEED` which had a signature change in sklearn 1.6+ (const qualifier added/removed). Even though we only needed `our_rand_r`, the signature mismatch caused import failures.
14+
15+
**Verification:**
16+
-`import causalml.dataset` succeeds
17+
- ✓ All tree-based modules import successfully
18+
- ✓ Test suite passes (109/109 tests)
19+
- ✓ No Cython signature errors
20+
21+
Tested with: Python 3.11.9, sklearn 1.7.0, scipy 1.17.0, numpy 2.1.3

0 commit comments

Comments
 (0)