• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MilesCranmer / PySR / 7375284807

01 Jan 2024 05:49AM UTC coverage: 90.283%. First build
7375284807

Pull #504

github

web-flow
Bump actions/setup-python from 4 to 5

Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #504: Bump actions/setup-python from 4 to 5

1022 of 1132 relevant lines covered (90.28%)

1.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/pysr/export_numpy.py
1
"""Code for exporting discovered expressions to numpy"""
2
import warnings
2✔
3

4
import numpy as np
2✔
5
import pandas as pd
2✔
6
from sympy import lambdify
2✔
7

8

9
def sympy2numpy(eqn, sympy_symbols, *, selection=None):
2✔
10
    return CallableEquation(eqn, sympy_symbols, selection=selection)
2✔
11

12

13
class CallableEquation:
2✔
14
    """Simple wrapper for numpy lambda functions built with sympy"""
15

16
    def __init__(self, eqn, sympy_symbols, selection=None):
2✔
17
        self._sympy = eqn
2✔
18
        self._sympy_symbols = sympy_symbols
2✔
19
        self._selection = selection
2✔
20

21
    def __repr__(self):
2✔
22
        return f"PySRFunction(X=>{self._sympy})"
2✔
23

24
    def __call__(self, X):
2✔
25
        expected_shape = (X.shape[0],)
2✔
26
        if isinstance(X, pd.DataFrame):
2✔
27
            # Lambda function takes as argument:
28
            return self._lambda(
2✔
29
                **{k: X[k].values for k in map(str, self._sympy_symbols)}
30
            ) * np.ones(expected_shape)
31
        if self._selection is not None:
2✔
32
            if X.shape[1] != len(self._selection):
2✔
33
                warnings.warn(
×
34
                    "`X` should be of shape (n_samples, len(self._selection)). "
35
                    "Automatically filtering `X` to selection. "
36
                    "Note: Filtered `X` column order may not match column order in fit "
37
                    "this may lead to incorrect predictions and other errors."
38
                )
39
                X = X[:, self._selection]
×
40
        return self._lambda(*X.T) * np.ones(expected_shape)
2✔
41

42
    @property
2✔
43
    def _lambda(self):
1✔
44
        return lambdify(self._sympy_symbols, self._sympy)
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc