Skip to content

Commit 8a1bb1b

Browse files
authored
Merge pull request #5481 from VesnaT/curve_fit
[ENH] Curve Fit: New widget
2 parents 1d3c728 + 63061cd commit 8a1bb1b

File tree

15 files changed

+1938
-5
lines changed

15 files changed

+1938
-5
lines changed

Orange/data/tests/test_util.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from Orange.data import Domain, ContinuousVariable
55
from Orange.data.util import get_unique_names, get_unique_names_duplicates, \
6-
get_unique_names_domain, one_hot
6+
get_unique_names_domain, one_hot, sanitized_name
77

88

99
class TestGetUniqueNames(unittest.TestCase):
@@ -260,5 +260,13 @@ def test_dim_too_low(self):
260260
one_hot(self.values, dim=2)
261261

262262

263+
class TestSanitizedName(unittest.TestCase):
264+
def test_sanitized_name(self):
265+
self.assertEqual(sanitized_name("Foo"), "Foo")
266+
self.assertEqual(sanitized_name("Foo Bar"), "Foo_Bar")
267+
self.assertEqual(sanitized_name("0Foo"), "_0Foo")
268+
self.assertEqual(sanitized_name("1 Foo Bar"), "_1_Foo_Bar")
269+
270+
263271
if __name__ == "__main__":
264272
unittest.main()

Orange/data/util.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,19 @@ def get_unique_names_domain(attributes, class_vars=(), metas=()):
268268
for old, new in zip(all_names, unique_names)
269269
if new != old))
270270
return (attributes, class_vars, metas), renamed
271+
272+
273+
def sanitized_name(name: str) -> str:
274+
"""
275+
Replace non-alphanumeric characters and leading zero with `_`.
276+
277+
Args:
278+
name (str): proposed name
279+
280+
Returns:
281+
name (str): new name
282+
"""
283+
sanitized = re.sub(r"\W", "_", name)
284+
if sanitized[0].isdigit():
285+
sanitized = "_" + sanitized
286+
return sanitized

Orange/regression/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pull members from modules to Orange.regression namespace
2-
# pylint: disable=wildcard-import
2+
# pylint: disable=wildcard-import,broad-except
33

44
from .base_regression import (ModelRegression as Model,
55
LearnerRegression as Learner,
@@ -23,3 +23,4 @@
2323
from .xgb import *
2424
except Exception:
2525
pass
26+
from .curvefit import *

0 commit comments

Comments
 (0)