Skip to content

Conversation

bessx
Copy link
Contributor

@bessx bessx commented Oct 13, 2025

Fix invalid escape sequence warnings in KCI and Kernel docstrings

This PR fixes SyntaxWarning: invalid escape sequence '\e' that appears on Python 3.12+ / 3.13 when importing causallearn.

Problem

Some docstrings in KCI.py and Kernel.py include LaTeX-like math expressions such as \epsilon.
In normal Python strings, \e is treated as an escape sequence, which is invalid and now triggers a warning:

.venv/lib/python3.13/site-packages/causallearn/utils/KCI/KCI.py:500: SyntaxWarning: invalid escape sequence '\e'
  With this we could save one repeated calculation of pinv(Kzy+\epsilonI), which consumes most time.
.venv/lib/python3.13/site-packages/causallearn/utils/KCI/Kernel.py:45: SyntaxWarning: invalid escape sequence '\e'
  Centers the kernel matrix via a centering matrix R=I-Kz(Kz+\epsilonI)^{-1} and returns RKR

Solution

  • Converted affected docstrings into raw strings (r"""...""").

Impact

  • No code or functional changes.
  • Silences warnings on Python 3.12+ and improves readability of the math in docstrings.
  • Keeps the intended LaTeX-style formatting intact for users and documentation tools.

@kunwuz kunwuz self-requested a review October 14, 2025 16:15
Copy link
Collaborator

@kunwuz kunwuz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks good!

@kunwuz kunwuz merged commit f179dd7 into py-why:main Oct 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants