Skip to content
Prev Previous commit
Next Next commit
docstring and typo
  • Loading branch information
sethah committed Mar 22, 2016
commit 66fe8fb277ad1fe0ff275750fc7f394b1eeb5ddf
35 changes: 19 additions & 16 deletions python/pyspark/ml/param/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def convertToList(value):

@staticmethod
def convertToListFloat(value):
"""
Convert a value to list of floats, if possible..
"""
if type(value) != list:
value = TypeConverters.convertToList(value)
try:
Expand All @@ -108,22 +111,10 @@ def convertToListFloat(value):
raise TypeError("Could not convert %s to a list of floats" % value)
return value

@staticmethod
def convertToVector(value):
"""
Convert a value to a Mllib Vector.
"""
if not isinstance(value, Vector):
try:
value = DenseVector(value)
except ValueError:
raise TypeError("Could not convert %s to a vector" % value)
return value

@staticmethod
def convertToListInt(value):
"""
Convert a value to list of ints.
Convert a value to list of ints, if possible..
"""
if type(value) != list:
value = TypeConverters.convertToList(value)
Expand All @@ -133,10 +124,22 @@ def convertToListInt(value):
raise TypeError("Could not convert %s to a list of ints" % value)
return value

@staticmethod
def convertToVector(value):
"""
Convert a value to a MLlib Vector, if possible..
"""
if not isinstance(value, Vector):
try:
value = DenseVector(value)
except ValueError:
raise TypeError("Could not convert %s to a vector" % value)
return value

@staticmethod
def convertToFloat(value):
"""
Convert a value to a float.
Convert a value to a float, if possible.
"""
try:
return float(value)
Expand All @@ -147,12 +150,12 @@ def convertToFloat(value):
@staticmethod
def convertToInt(value):
"""
Convert a value to an int.
Convert a value to an int, if possible..
"""
try:
return int(value)
except ValueError:
raise TypeError("Could not convert %s to float" % int)
raise TypeError("Could not convert %s to int" % value)


class Params(Identifiable):
Expand Down