Spaces:
Running
Running
MilesCranmer
commited on
Commit
β’
13d5805
1
Parent(s):
ad6d652
Fix for when pretty_feature_names_in_ is undefined
Browse files- pysr/sr.py +10 -3
pysr/sr.py
CHANGED
@@ -1367,7 +1367,10 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
1367 |
"Using DataFrame column names instead."
|
1368 |
)
|
1369 |
|
1370 |
-
if
|
|
|
|
|
|
|
1371 |
X.columns = X.columns.str.replace(" ", "_")
|
1372 |
warnings.warn(
|
1373 |
"Spaces in DataFrame column names are not supported. "
|
@@ -1726,7 +1729,8 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
1726 |
niterations=int(self.niterations),
|
1727 |
variable_names=(
|
1728 |
self.pretty_feature_names_in_.tolist()
|
1729 |
-
if self
|
|
|
1730 |
else self.feature_names_in_.tolist()
|
1731 |
),
|
1732 |
options=options,
|
@@ -2123,7 +2127,10 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
2123 |
},
|
2124 |
)
|
2125 |
# Regexp replace xβββ to x123 in `equation`:
|
2126 |
-
if
|
|
|
|
|
|
|
2127 |
# df["equation"] = df["equation"].apply(_undo_subscriptify_full)
|
2128 |
for pname, name in zip(
|
2129 |
self.pretty_feature_names_in_, self.feature_names_in_
|
|
|
1367 |
"Using DataFrame column names instead."
|
1368 |
)
|
1369 |
|
1370 |
+
if (
|
1371 |
+
pd.api.types.is_object_dtype(X.columns)
|
1372 |
+
and X.columns.str.contains(" ").any()
|
1373 |
+
):
|
1374 |
X.columns = X.columns.str.replace(" ", "_")
|
1375 |
warnings.warn(
|
1376 |
"Spaces in DataFrame column names are not supported. "
|
|
|
1729 |
niterations=int(self.niterations),
|
1730 |
variable_names=(
|
1731 |
self.pretty_feature_names_in_.tolist()
|
1732 |
+
if hasattr(self, "pretty_feature_names_in_")
|
1733 |
+
and self.pretty_feature_names_in_ is not None
|
1734 |
else self.feature_names_in_.tolist()
|
1735 |
),
|
1736 |
options=options,
|
|
|
2127 |
},
|
2128 |
)
|
2129 |
# Regexp replace xβββ to x123 in `equation`:
|
2130 |
+
if (
|
2131 |
+
hasattr(self, "pretty_feature_names_in_")
|
2132 |
+
and self.pretty_feature_names_in_ is not None
|
2133 |
+
):
|
2134 |
# df["equation"] = df["equation"].apply(_undo_subscriptify_full)
|
2135 |
for pname, name in zip(
|
2136 |
self.pretty_feature_names_in_, self.feature_names_in_
|