Skip to content

Fix NameError in F_PSignature on Python 3.13 (#179)#194

Merged
khasawn3 merged 2 commits into
TeaspoonTDA:masterfrom
OmerJauhar:fix-179
Jun 2, 2026
Merged

Fix NameError in F_PSignature on Python 3.13 (#179)#194
khasawn3 merged 2 commits into
TeaspoonTDA:masterfrom
OmerJauhar:fix-179

Conversation

@OmerJauhar

Copy link
Copy Markdown
Contributor

Description

The F_PSignature function used exec() to create dynamically-named local variables and read them in a second exec() call. This worked on older Python because both exec() calls shared the same locals dict, but Python 3.13 changed locals() to return a fresh snapshot each call (PEP 667), so the second exec couldn't see what the first one defined.

The fix replaces the two exec() calls with a regular Python list of sympy expressions indexed by segment. No string templating, no scope tricks, and the math is unchanged.

Motivation and Context

Fixes #179. The path signature classification example from the docs (https://teaspoontda.github.io/teaspoon/modules/ML/CL_PS.html) crashes on Python 3.13 with NameError: name 'f_1_1_case1' is not defined, which makes the documented workflow unusable on the latest Python.

How has this been tested?

  • Reproduced the original NameError on Python 3.13.13 using the upstream teaspoon 1.5.30 from pip.
  • Confirmed the patched version runs the documented CL_PS example end-to-end on Python 3.13.13.
  • Compared output against the original on Python 3.10 across 24 diagrams with L=[1] and 23 diagrams with L=[1,2]: max absolute difference is 0.0 (bitwise identical).
  • Verified algebraic equivalence of the rewritten linear-segment formula with sympy.simplify (difference is 0).
  • Existing unit tests still pass: tests/test_classification.py and tests/test_featureFunctions.py (4 passed).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project. (make clean)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (make html)
  • I have incremented the version number in the pyproject.toml file.
  • I have added tests to cover my changes.
  • All new and existing tests passed. (make tests)

…and read them in a second exec() call. This worked on older Python because both exec() calls shared the same locals dict, but Python 3.13 changed locals() to return a fresh snapshot each call, so the second exec couldn't see what the first one defined.
@khasawn3 khasawn3 self-assigned this Jun 2, 2026
@khasawn3 khasawn3 self-requested a review June 2, 2026 01:27
@khasawn3 khasawn3 merged commit 6db9419 into TeaspoonTDA:master Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants