MilesCranmer commited on
Commit
6088859
1 Parent(s): 6248183

docs: better formatting for errors

Browse files
Files changed (2) hide show
  1. pysr/sr.py +7 -5
  2. pysr/test/test.py +6 -4
pysr/sr.py CHANGED
@@ -884,15 +884,15 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
884
  updated_kwarg_name = DEPRECATED_KWARGS[k]
885
  setattr(self, updated_kwarg_name, v)
886
  warnings.warn(
887
- f"{k} has been renamed to {updated_kwarg_name} in PySRRegressor. "
888
  "Please use that instead.",
889
  FutureWarning,
890
  )
891
  # Handle kwargs that have been moved to the fit method
892
  elif k in ["weights", "variable_names", "Xresampled"]:
893
  warnings.warn(
894
- f"{k} is a data dependant parameter so should be passed when fit is called. "
895
- f"Ignoring parameter; please pass {k} during the call to fit instead.",
896
  FutureWarning,
897
  )
898
  elif k == "julia_project":
@@ -910,9 +910,11 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
910
  )
911
  else:
912
  suggested_keywords = _suggest_keywords(PySRRegressor, k)
913
- err_msg = f"{k} is not a valid keyword argument for PySRRegressor."
 
 
914
  if len(suggested_keywords) > 0:
915
- err_msg += f" Did you mean {' or '.join(suggested_keywords)}?"
916
  raise TypeError(err_msg)
917
 
918
  @classmethod
 
884
  updated_kwarg_name = DEPRECATED_KWARGS[k]
885
  setattr(self, updated_kwarg_name, v)
886
  warnings.warn(
887
+ f"`{k}` has been renamed to `{updated_kwarg_name}` in PySRRegressor. "
888
  "Please use that instead.",
889
  FutureWarning,
890
  )
891
  # Handle kwargs that have been moved to the fit method
892
  elif k in ["weights", "variable_names", "Xresampled"]:
893
  warnings.warn(
894
+ f"`{k}` is a data-dependent parameter and should be passed when fit is called. "
895
+ f"Ignoring parameter; please pass `{k}` during the call to fit instead.",
896
  FutureWarning,
897
  )
898
  elif k == "julia_project":
 
910
  )
911
  else:
912
  suggested_keywords = _suggest_keywords(PySRRegressor, k)
913
+ err_msg = (
914
+ f"`{k}` is not a valid keyword argument for PySRRegressor."
915
+ )
916
  if len(suggested_keywords) > 0:
917
+ err_msg += f" Did you mean {', '.join(map(lambda s: f'`{s}`', suggested_keywords))}?"
918
  raise TypeError(err_msg)
919
 
920
  @classmethod
pysr/test/test.py CHANGED
@@ -819,16 +819,18 @@ class TestHelpMessages(unittest.TestCase):
819
  with self.assertRaises(TypeError) as cm:
820
  model = PySRRegressor(ncyclesperiterationn=5)
821
 
822
- self.assertIn("ncyclesperiterationn is not a valid keyword", str(cm.exception))
 
 
823
  self.assertIn("Did you mean", str(cm.exception))
824
- self.assertIn("ncycles_per_iteration or", str(cm.exception))
825
- self.assertIn("niteration", str(cm.exception))
826
 
827
  # Farther matches (this might need to be changed)
828
  with self.assertRaises(TypeError) as cm:
829
  model = PySRRegressor(operators=["+", "-"])
830
 
831
- self.assertIn("unary_operators or binary_operators", str(cm.exception))
832
 
833
 
834
  TRUE_PREAMBLE = "\n".join(
 
819
  with self.assertRaises(TypeError) as cm:
820
  model = PySRRegressor(ncyclesperiterationn=5)
821
 
822
+ self.assertIn(
823
+ "`ncyclesperiterationn` is not a valid keyword", str(cm.exception)
824
+ )
825
  self.assertIn("Did you mean", str(cm.exception))
826
+ self.assertIn("`ncycles_per_iteration`, ", str(cm.exception))
827
+ self.assertIn("`niterations`", str(cm.exception))
828
 
829
  # Farther matches (this might need to be changed)
830
  with self.assertRaises(TypeError) as cm:
831
  model = PySRRegressor(operators=["+", "-"])
832
 
833
+ self.assertIn("`unary_operators`, `binary_operators`", str(cm.exception))
834
 
835
 
836
  TRUE_PREAMBLE = "\n".join(