0

I get the following error in the code below. It would be great if someone can help me understand what the error is and how can it be bypassed

charcols = [item[0] for item in training_data.dtypes if item[1].endswith('string')]
Indexer = StringIndexer(inputCol = charcols[0], outputCol=charcols[0]+ "indexed", handleInvalid="skip")
indexer_fit = Indexer.fit(training_data)
training_data = indexer_fit.transform(training_data)
dmp = pickle.dumps(indexer_fit)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/hdp/current/spark2-client/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
  File "/usr/hdp/current/spark2-client/python/pyspark/sql/utils.py", line 63, in deco
    return f(*a, **kw)
File "/usr/hdp/current/spark2-client/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 323, in get_return_value
py4j.protocol.Py4JError: An error occurred while calling o59.__getstate__. Trace:
py4j.Py4JException: Method __getstate__([]) does not exist
        at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
        at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
        at py4j.Gateway.invoke(Gateway.java:272)
        at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
        at py4j.commands.CallCommand.execute(CallCommand.java:79)
        at py4j.GatewayConnection.run(GatewayConnection.java:214)
        at java.lang.Thread.run(Thread.java:748)
Rajarshi Bhadra
  • 1,826
  • 6
  • 25
  • 41
  • What are you trying to achieve by pickling the model? If you want to save it to a disk or HDFS, just use `write()` method https://spark.apache.org/docs/2.0.1/api/java/org/apache/spark/ml/feature/StringIndexerModel.html#write() – Sergey Khudyakov Jul 19 '18 at 11:18
  • I want to create a customStringIndexer transformer where the string indexing happens column by column via a pipeline created in the fit method. Going by the method as given in the link https://stackoverflow.com/questions/41399399/serialize-a-custom-transformer-using-python-to-be-used-within-a-pyspark-ml-pipel I am facing the error when I try to save my custom Transformer – Rajarshi Bhadra Jul 19 '18 at 11:41

0 Answers0