Skip to content

Commit fd1f464

Browse files
authored
BUG: repr for Cal objects (#217) (#1137)
Co-authored-by: JHM Darbyshire (M1) <[email protected]>
1 parent e749bc5 commit fd1f464

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

python/tests/serialization/test_repr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from rateslib import dt
33
from rateslib.dual import Dual, Dual2
4-
from rateslib.scheduling import Adjuster, Frequency, Imm, NamedCal, RollDay, Schedule, StubInference
4+
from rateslib.scheduling import Adjuster, Frequency, Imm, Cal, UnionCal, NamedCal, RollDay, Schedule, StubInference
55
from rateslib.splines import PPSplineDual, PPSplineDual2, PPSplineF64
66

77

@@ -35,6 +35,9 @@
3535
),
3636
"PPSplineDual2",
3737
),
38+
(Cal([],[]), "Cal"),
39+
(UnionCal([Cal([],[]), Cal([],[])], []), "UnionCal"),
40+
(NamedCal("tgt,ldn|fed"), "NamedCal:'tgt,ldn|fed'"),
3841
],
3942
)
4043
def test_repr_strings(obj, expected) -> None:

rust/scheduling/py/calendar.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ impl Cal {
382382
Calendar::NamedCal(c) => *self == c,
383383
}
384384
}
385+
386+
fn __repr__(&self) -> String {
387+
format!("<rl.Cal at {:p}>", self)
388+
}
385389
}
386390

387391
#[pymethods]
@@ -591,6 +595,10 @@ impl UnionCal {
591595
Calendar::NamedCal(c) => *self == c,
592596
}
593597
}
598+
599+
fn __repr__(&self) -> String {
600+
format!("<rl.UnionCal at {:p}>", self)
601+
}
594602
}
595603

596604
#[pymethods]
@@ -790,6 +798,10 @@ impl NamedCal {
790798
Calendar::NamedCal(c) => *self == c,
791799
}
792800
}
801+
802+
fn __repr__(&self) -> String {
803+
format!("<rl.NamedCal:'{}' at {:p}>", self.name, self)
804+
}
793805
}
794806

795807
#[cfg(test)]

0 commit comments

Comments
 (0)