Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-51015][ML][PYTHON][CONNECT] Support RFormulaModel.toString on Connect #49745

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -387,6 +387,10 @@ class RFormulaModel private[feature](
s"RFormulaModel: uid=$uid, resolvedFormula=$resolvedFormula"
}

// For ml connect only
@Since("4.0.0")
private[ml] def resolvedFormulaString: String = resolvedFormula.toString

private def transformLabel(dataset: Dataset[_]): DataFrame = {
val labelName = resolvedFormula.label
if (labelName.isEmpty || hasLabelCol(dataset.schema)) {
2 changes: 1 addition & 1 deletion python/pyspark/ml/feature.py
Original file line number Diff line number Diff line change
@@ -6841,7 +6841,7 @@ class RFormulaModel(JavaModel, _RFormulaParams, JavaMLReadable["RFormulaModel"],
"""

def __str__(self) -> str:
resolvedFormula = self._call_java("resolvedFormula")
resolvedFormula = self._call_java("resolvedFormulaString")
return "RFormulaModel(%s) (uid=%s)" % (resolvedFormula, self.uid)


3 changes: 1 addition & 2 deletions python/pyspark/ml/tests/test_feature.py
Original file line number Diff line number Diff line change
@@ -1312,8 +1312,7 @@ def test_rformula_string_indexer_order_type(self):

model.write().overwrite().save(d)
model2 = RFormulaModel.load(d)
# TODO: fix str(model)
# self.assertEqual(str(model), str(model2))
self.assertEqual(str(model), str(model2))
self.assertEqual(model.getFormula(), model2.getFormula())

def test_string_indexer_handle_invalid(self):
Original file line number Diff line number Diff line change
@@ -648,6 +648,7 @@ private[ml] object MLUtils {
(classOf[CountVectorizerModel], Set("vocabulary")),
(classOf[OneHotEncoderModel], Set("categorySizes")),
(classOf[StringIndexerModel], Set("labels", "labelsArray")),
(classOf[RFormulaModel], Set("resolvedFormulaString")),
(classOf[IDFModel], Set("idf", "docFreq", "numDocs")))

private def validate(obj: Any, method: String): Unit = {