Repository: mlflow/mlflow

Issue:
Issue While Serializing Model When Logging With Mlflow Mleap
I am facing an issue when logging my model through the mlflow.mleap.log_model function. Below are my following settings:

I created an experiment with the local file path set as the artifact_location argument.

mlflow.create_experiment\
    (
        name="decision_tree",
        artifact_location="file:/D:/Mlflow/artifacts",
        tags={"version":"v1","priority":"p1"},
    )
  
I used the spark model sample code written on the [mlflow mleap](https://www.mlflow.org/docs/latest/python_api/mlflow.mleap.html) page. 

![image](https://user-images.githubusercontent.com/61215448/193506309-2253b26a-d312-4486-a1c0-5a6ac609a2dd.png)

However, when I call the mlflow.mleap method, it raises the following issue:

![image](https://user-images.githubusercontent.com/61215448/193506406-b87855aa-2326-4078-8148-0ef23588f706.png)

I have tried to change the artifact location to different local path files and even HDFS path, but the same issue occurs. Kindly look into this and let me know if it is an issue from my side.
    


Discussion:

Resolving patch:
diff --git a/mlflow/mleap.py b/mlflow/mleap.py
--- a/mlflow/mleap.py
+++ b/mlflow/mleap.py
@@ -10,6 +10,7 @@
 """
 import logging
 import os
+import pathlib
 import sys
 import traceback
 
@@ -20,6 +21,7 @@
 from mlflow.models.signature import ModelSignature
 from mlflow.models.utils import ModelInputExample, _save_example
 from mlflow.utils import reraise
+from mlflow.utils.file_utils import path_to_local_file_uri
 from mlflow.utils.annotations import keyword_only
 
 FLAVOR_NAME = "mleap"
@@ -243,7 +245,15 @@ def add_to_model(mlflow_model, path, spark_model, sample_input):
     os.makedirs(mleap_path_full)
 
     dataset = spark_model.transform(sample_input)
-    model_path = "file:{mp}".format(mp=mleap_datapath_full)
+    if os.name == "nt":
+        # NB: On Windows, MLeap requires the "file://" prefix in order to correctly
+        # parse the model data path, even though the result is not a correct URI.
+        # None of "file:", "file:/", or "file:///", which would be canonically correct,
+        # work properly
+        model_path = "file://" + str(pathlib.Path(mleap_datapath_full).as_posix())
+    else:
+        model_path = path_to_local_file_uri(mleap_datapath_full)
+
     try:
         spark_model.serializeToBundle(path=model_path, dataset=dataset)
     except Py4JError:
diff --git a/mlflow/utils/file_utils.py b/mlflow/utils/file_utils.py
--- a/mlflow/utils/file_utils.py
+++ b/mlflow/utils/file_utils.py
@@ -517,11 +517,7 @@ def path_to_local_file_uri(path):
     """
     Convert local filesystem path to local file uri.
     """
-    path = pathname2url(path)
-    if path == posixpath.abspath(path):
-        return "file://{path}".format(path=path)
-    else:
-        return "file:{path}".format(path=path)
+    return pathlib.Path(os.path.abspath(path)).as_uri()
 
 
 def path_to_local_sqlite_uri(path):


Test patch:
diff --git a/tests/mleap/test_mleap_model_export.py b/tests/mleap/test_mleap_model_export.py
--- a/tests/mleap/test_mleap_model_export.py
+++ b/tests/mleap/test_mleap_model_export.py
@@ -1,5 +1,6 @@
 import json
 import os
+import sys
 from unittest import mock
 from packaging.version import Version
 
@@ -54,6 +55,10 @@ def spark_context():
     spark_session.stop()
 
 
+@pytest.mark.skipif(
+    not sys.platform.startswith("linux"),
+    reason="Docker image resolution for non-linux tests is not supported",
+)
 def test_model_deployment(spark_model_iris, model_path, spark_custom_env):
     mlflow.spark.save_model(
         spark_model_iris.model,