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

MilesCranmer / PySR / 10138721258

29 Jul 2024 05:35AM UTC coverage: 93.448% (-0.3%) from 93.797%
10138721258

Pull #681

github

web-flow
Merge 7af2bd516 into 3aee19e38
Pull Request #681: Enhance cross-platform compatibility for loading PySRRegressor models

15 of 17 new or added lines in 2 files covered. (88.24%)

3 existing lines in 1 file now uncovered.

1141 of 1221 relevant lines covered (93.45%)

2.59 hits per line

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

92.86
/pysr/utils.py
1
import difflib
3✔
2
import inspect
3✔
3
import os
3✔
4
import pickle as pkl
3✔
5
import re
3✔
6
from pathlib import Path, PurePosixPath, PureWindowsPath
3✔
7
from typing import Any, List, TypeVar, Union
3✔
8

9
from numpy import ndarray
3✔
10
from sklearn.utils.validation import _check_feature_names_in  # type: ignore
3✔
11

12
T = TypeVar("T", bound=Any)
3✔
13

14
ArrayLike = Union[ndarray, List[T]]
3✔
15
PathLike = Union[str, Path]
3✔
16

17

18
def _csv_filename_to_pkl_filename(csv_filename: PathLike) -> PathLike:
3✔
19
    if os.path.splitext(csv_filename)[1] == ".pkl":
3✔
20
        return csv_filename
3✔
21

22
    # Assume that the csv filename is of the form "foo.csv"
23
    assert str(csv_filename).endswith(".csv")
3✔
24

25
    dirname = str(os.path.dirname(csv_filename))
3✔
26
    basename = str(os.path.basename(csv_filename))
3✔
27
    base = str(os.path.splitext(basename)[0])
3✔
28

29
    pkl_basename = base + ".pkl"
3✔
30

31
    return os.path.join(dirname, pkl_basename)
3✔
32

33

34
_regexp_im = re.compile(r"\b(\d+\.\d+)im\b")
3✔
35
_regexp_im_sci = re.compile(r"\b(\d+\.\d+)[eEfF]([+-]?\d+)im\b")
3✔
36
_regexp_sci = re.compile(r"\b(\d+\.\d+)[eEfF]([+-]?\d+)\b")
3✔
37

38
_apply_regexp_im = lambda x: _regexp_im.sub(r"\1j", x)
3✔
39
_apply_regexp_im_sci = lambda x: _regexp_im_sci.sub(r"\1e\2j", x)
3✔
40
_apply_regexp_sci = lambda x: _regexp_sci.sub(r"\1e\2", x)
3✔
41

42

43
def _preprocess_julia_floats(s: str) -> str:
3✔
44
    if isinstance(s, str):
3✔
45
        s = _apply_regexp_im(s)
3✔
46
        s = _apply_regexp_im_sci(s)
3✔
47
        s = _apply_regexp_sci(s)
3✔
48
    return s
3✔
49

50

51
def _safe_check_feature_names_in(self, variable_names, generate_names=True):
3✔
52
    """_check_feature_names_in with compat for old versions."""
53
    try:
3✔
54
        return _check_feature_names_in(
3✔
55
            self, variable_names, generate_names=generate_names
56
        )
57
    except TypeError:
×
58
        return _check_feature_names_in(self, variable_names)
×
59

60

61
def _subscriptify(i: int) -> str:
3✔
62
    """Converts integer to subscript text form.
63

64
    For example, 123 -> "₁₂₃".
65
    """
66
    return "".join([chr(0x2080 + int(c)) for c in str(i)])
3✔
67

68

69
def _suggest_keywords(cls, k: str) -> List[str]:
3✔
70
    valid_keywords = [
3✔
71
        param
72
        for param in inspect.signature(cls.__init__).parameters
73
        if param not in ["self", "kwargs"]
74
    ]
75
    suggestions = difflib.get_close_matches(k, valid_keywords, n=3)
3✔
76
    return suggestions
3✔
77

78

79
class _CrossPlatformPathUnpickler(pkl.Unpickler):
3✔
80
    def find_class(self, module, name):
3✔
81
        if module == "pathlib":
3✔
82
            if name == "PosixPath":
3✔
83
                return PurePosixPath
3✔
NEW
84
            elif name == "WindowsPath":
×
NEW
85
                return PureWindowsPath
×
86
        return super().find_class(module, name)
3✔
87

88

89
def _path_to_str(path):
3✔
90
    if isinstance(path, (PurePosixPath, PureWindowsPath)):
3✔
91
        return str(path)
3✔
92
    return path
3✔
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