Skip to content

Commit 1f9e8a2

Browse files
avhzavhz
authored andcommitted
fix: pyo3 test/example errors on MacOS
1 parent 989ad39 commit 1f9e8a2

File tree

19 files changed

+101
-276
lines changed

19 files changed

+101
-276
lines changed

Cargo.toml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ rustdoc-args = ["--html-in-header", "katex.html", "--cfg", "docsrs"]
6868
RustQuant_autodiff = { version = "0.4.0", path = "crates/RustQuant_autodiff" }
6969
RustQuant_cashflows = { version = "0.4.0", path = "crates/RustQuant_cashflows" }
7070
RustQuant_data = { version = "0.4.0", path = "crates/RustQuant_data" }
71+
RustQuant_enums = { version = "0.4.0", path = "crates/RustQuant_enums" }
7172
RustQuant_error = { version = "0.4.0", path = "crates/RustQuant_error" }
7273
RustQuant_instruments = { version = "0.4.0", path = "crates/RustQuant_instruments" }
7374
RustQuant_iso = { version = "0.4.0", path = "crates/RustQuant_iso" }
@@ -116,17 +117,4 @@ polars = { version = "0.44.0", features = ["docs-selection"] }
116117
serde = { version = "1.0.213", features = ["derive"] }
117118

118119
# https://docs.rs/crate/pyo3/latest
119-
pyo3 = {version = "0.26.0", features = ["extension-module", "time"]}
120-
121-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122-
## PYTHON BINDINGS
123-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124-
125-
# [lib]
126-
# name = "RustQuant"
127-
# crate-type = ["cdylib"]
128-
129-
# [dependencies.pyo3]
130-
# version = "0.22.0"
131-
# features = ["extension-module"]
132-
# features = ["abi3-py37", "extension-module"]
120+
pyo3 = {version = "0.26.0", features = ["time"] }

bindings/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ name = "RustQuant_pyo3"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
76
[lib]
87
name = "RustQuant"
98
crate-type = ["cdylib"]
109
path = "rust/lib.rs"
1110

1211
[dependencies]
1312
RustQuant = {path = "../crates/RustQuant"}
14-
pyo3 = {workspace = true}
15-
time = { workspace = true }
13+
pyo3 = { workspace = true }
14+
time = { workspace = true }

bindings/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ build-backend = "maturin"
44

55
[project]
66
name = "RustQuant"
7+
dynamic = ["version"]
78
requires-python = ">=3.8"
89
classifiers = [
910
"Programming Language :: Rust",
1011
"Programming Language :: Python :: Implementation :: CPython",
1112
"Programming Language :: Python :: Implementation :: PyPy",
1213
]
13-
dynamic = ["version"]
14+
1415
[tool.maturin]
15-
features = ["pyo3/extension-module"]
1616
python-source = "python"
17+
features = ["pyo3/extension-module"]

bindings/testing.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
from pprint import pprint as print
22
from datetime import date
3+
34
from RustQuant.data import (
4-
SpotCurve,
5-
PyCurve,
5+
Curve,
66
CurveType,
77
InterpolationMethod,
88
)
99
from RustQuant.time import (
1010
Calendar,
1111
Market,
1212
)
13-
import RustQuant.data
14-
import RustQuant
1513

16-
RustQuant.data.SpotCurve.new()
17-
RustQuant.__dir__()
18-
RustQuant.data.__dir__()
1914

2015
dates = [
2116
date(2026, 1, 1),
@@ -32,7 +27,7 @@
3227
0.013,
3328
]
3429

35-
crv = PyCurve(dates, rates, CurveType.Spot, InterpolationMethod.Linear)
30+
crv = Curve(dates, rates, CurveType.Spot, InterpolationMethod.Linear)
3631
print(crv.get_rate(date(2026, 6, 1)))
3732

3833

@@ -44,14 +39,6 @@
4439
date(2026, 6, 5),
4540
]
4641

47-
curve = SpotCurve(dates, rates)
48-
print(curve.__dir__())
49-
50-
curve.plot()
51-
curve.get_rates(new_dates)
52-
53-
curve.fit()
54-
5542
cal = Calendar(Market.Australia)
5643
print(cal.__dir__())
5744
cal.market()

crates/RustQuant/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
## - LICENSE-MIT.md
88
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99

10-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11-
## GENERAL CONFIGURATION
12-
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13-
1410
[package]
1511
name = "RustQuant"
1612

@@ -35,12 +31,14 @@ workspace = true
3531
RustQuant_autodiff = { workspace = true }
3632
RustQuant_cashflows = { workspace = true }
3733
RustQuant_data = { workspace = true }
34+
RustQuant_enums = { workspace = true }
3835
RustQuant_error = { workspace = true }
3936
RustQuant_instruments = { workspace = true }
4037
RustQuant_iso = { workspace = true }
4138
RustQuant_math = { workspace = true }
4239
RustQuant_ml = { workspace = true }
4340
RustQuant_portfolios = { workspace = true }
41+
RustQuant_pricing = { workspace = true }
4442
RustQuant_stochastics = { workspace = true }
4543
RustQuant_time = { workspace = true }
4644
RustQuant_trading = { workspace = true }

crates/RustQuant_data/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ time = { workspace = true }
3030
plotly = { workspace = true }
3131
argmin = { workspace = true }
3232
argmin-math = { workspace = true }
33-
pyo3 = {workspace=true}
33+
pyo3 = { workspace = true }
34+
3435

3536
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3637
## RUSTDOC CONFIGURATION

crates/RustQuant_data/src/curves.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,31 @@ impl Curve {
179179
}
180180
}
181181

182+
/// Get a rate, and simultaneously add it to the nodes.
183+
pub fn get_rate_and_insert(&mut self, date: Date) -> Option<f64> {
184+
match self.nodes.get(&date) {
185+
Some(rate) => Some(*rate),
186+
None => {
187+
let rate = self.interpolator.interpolate(date).ok()?;
188+
self.nodes.insert(date, rate);
189+
Some(rate)
190+
}
191+
}
192+
}
193+
182194
/// Get multiple rates from the curve.
183195
pub fn get_rates(&self, dates: Vec<Date>) -> Vec<Option<f64>> {
184196
dates.iter().map(|date| self.get_rate(*date)).collect()
185197
}
186198

199+
/// Get multiple rates from the curve, and simultaneously add them to the nodes.
200+
pub fn get_rates_and_insert(&mut self, dates: Vec<Date>) -> Vec<Option<f64>> {
201+
dates
202+
.iter()
203+
.map(|date| self.get_rate_and_insert(*date))
204+
.collect()
205+
}
206+
187207
/// Set a rate in the curve.
188208
pub fn set_rate(&mut self, date: Date, rate: f64) {
189209
self.nodes.insert(date, rate);

crates/RustQuant_enums/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "RustQuant_enums"
3+
authors.workspace = true
4+
description.workspace = true
5+
version.workspace = true
6+
edition.workspace = true
7+
readme.workspace = true
8+
repository.workspace = true
9+
keywords.workspace = true
10+
categories.workspace = true
11+
license.workspace = true
12+
metadata.workspace = true
13+
14+
[dependencies]
15+
16+
[lints]
17+
workspace = true

crates/RustQuant_enums/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! RustQuant_enums crate.
2+
//!
3+
//! This crate is used solely to avoid circular dependencies
4+
//! between other crates in the RustQuant workspace.

crates/RustQuant_error/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ workspace = true
1717
[dependencies]
1818
thiserror = { workspace = true }
1919
rand_distr = { workspace = true }
20-
pyo3 = {workspace = true}
20+
pyo3 = { workspace = true }
21+
2122

2223
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2324
## RUSTDOC CONFIGURATION

0 commit comments

Comments
 (0)