Repository navigation
Fix barssince() TypeError on scalar input (e.g. cross()) - #1422
Geochelone666 wants to merge 3 commits into
Conversation
|
Reproduced on the released 0.6.6 in a clean venv: Two small things I would look at:
The new tests look right to me; |
|
Thanks for the thorough review! Addressed both points in 8691f7e:
Extended |
|
Read the new diff: |
Lock in the 0-d branch side effect noted in review: barssince(None)
returns default (falsy), barssince('a') returns 0 (truthy); both used
to raise TypeError. Extends test_barssince_scalar.
|
Good catch, thanks. I've added regression tests locking this in: |
Bug
barssince(cross(...))raisedTypeError: object of type 'numpy.bool_' has no len()becausecross()returns a scalarnumpy.bool_whilebarssinceexpected a sequence (Sequence[bool]).Fix
barssincenow accepts scalarbool/np.bool_gracefully: scalarTruereturns 0 ("just happened"), scalarFalsereturnsdefault. Docstring updated to document the semantics. Behavior for sequence inputs is unchanged.Tests
3 new regression tests in
backtesting/test/_test.py:test_barssince_scalar(bool/np.bool_ True/False, default inf/-1)test_barssince_cross(the exact issue scenario:barssince(cross(...)))test_barssince_sequences(list/tuple/ndarray behavior unchanged)Verified: old code raises the reported TypeError; new code handles scalars and preserves sequence behavior.
Note: patch prepared with AI assistance (Claude Codex) and reviewed by a human coordinator.
Fixes #1259.