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-33457][PYTHON] Adjust mypy configuration #30382

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
87 changes: 87 additions & 0 deletions python/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,97 @@
;

[mypy]
strict_optional = True
no_implicit_optional = True
disallow_untyped_defs = True

; Allow untyped def in internal modules and tests

[mypy-pyspark.daemon]
disallow_untyped_defs = False

[mypy-pyspark.find_spark_home]
disallow_untyped_defs = False

[mypy-pyspark._globals]
disallow_untyped_defs = False

[mypy-pyspark.install]
disallow_untyped_defs = False

[mypy-pyspark.java_gateway]
disallow_untyped_defs = False

[mypy-pyspark.join]
disallow_untyped_defs = False

[mypy-pyspark.ml.tests.*]
disallow_untyped_defs = False

[mypy-pyspark.mllib.tests.*]
disallow_untyped_defs = False

[mypy-pyspark.rddsampler]
disallow_untyped_defs = False

[mypy-pyspark.resource.tests.*]
disallow_untyped_defs = False

[mypy-pyspark.serializers]
disallow_untyped_defs = False

[mypy-pyspark.shuffle]
disallow_untyped_defs = False

[mypy-pyspark.streaming.tests.*]
disallow_untyped_defs = False

[mypy-pyspark.streaming.util]
disallow_untyped_defs = False

[mypy-pyspark.sql.tests.*]
disallow_untyped_defs = False

[mypy-pyspark.sql.pandas.serializers]
disallow_untyped_defs = False

[mypy-pyspark.sql.pandas.types]
disallow_untyped_defs = False

[mypy-pyspark.sql.pandas.typehints]
disallow_untyped_defs = False

[mypy-pyspark.sql.pandas.utils]
disallow_untyped_defs = False

[mypy-pyspark.sql.pandas._typing.protocols.*]
disallow_untyped_defs = False

[mypy-pyspark.sql.utils]
disallow_untyped_defs = False

[mypy-pyspark.tests.*]
disallow_untyped_defs = False

[mypy-pyspark.testing.*]
disallow_untyped_defs = False

[mypy-pyspark.traceback_utils]
disallow_untyped_defs = False

[mypy-pyspark.util]
disallow_untyped_defs = False

[mypy-pyspark.worker]
disallow_untyped_defs = False

; Ignore errors in embedded third party code

[mypy-pyspark.cloudpickle.*]
ignore_errors = True

; Ignore missing imports for external untyped packages

[mypy-py4j.*]
ignore_missing_imports = True

Expand Down
10 changes: 5 additions & 5 deletions python/pyspark/broadcast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.

import threading
from typing import Any, Dict, Generic, Optional, TypeVar
from typing import Any, Callable, Dict, Generic, Optional, Tuple, TypeVar

T = TypeVar("T")

Expand All @@ -32,14 +32,14 @@ class Broadcast(Generic[T]):
path: Optional[Any] = ...,
sock_file: Optional[Any] = ...,
) -> None: ...
def dump(self, value: Any, f: Any) -> None: ...
def load_from_path(self, path: Any): ...
def load(self, file: Any): ...
def dump(self, value: T, f: Any) -> None: ...
def load_from_path(self, path: Any) -> T: ...
def load(self, file: Any) -> T: ...
@property
def value(self) -> T: ...
def unpersist(self, blocking: bool = ...) -> None: ...
def destroy(self, blocking: bool = ...) -> None: ...
def __reduce__(self): ...
def __reduce__(self) -> Tuple[Callable[[int], T], Tuple[int]]: ...

class BroadcastPickleRegistry(threading.local):
def __init__(self) -> None: ...
Expand Down
25 changes: 21 additions & 4 deletions python/pyspark/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@
# specific language governing permissions and limitations
# under the License.

from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, TypeVar
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
NoReturn,
Optional,
Tuple,
Type,
TypeVar,
)
from types import TracebackType

from py4j.java_gateway import JavaGateway, JavaObject # type: ignore[import]

Expand Down Expand Up @@ -51,9 +63,14 @@ class SparkContext:
jsc: Optional[JavaObject] = ...,
profiler_cls: type = ...,
) -> None: ...
def __getnewargs__(self): ...
def __enter__(self): ...
def __exit__(self, type, value, trace): ...
def __getnewargs__(self) -> NoReturn: ...
def __enter__(self) -> SparkContext: ...
def __exit__(
self,
type: Optional[Type[BaseException]],
value: Optional[BaseException],
trace: Optional[TracebackType],
) -> None: ...
@classmethod
def getOrCreate(cls, conf: Optional[SparkConf] = ...) -> SparkContext: ...
def setLogLevel(self, logLevel: str) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions python/pyspark/ml/classification.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _JavaProbabilisticClassifier(
class _JavaProbabilisticClassificationModel(
ProbabilisticClassificationModel, _JavaClassificationModel[T]
):
def predictProbability(self, value: Any): ...
def predictProbability(self, value: Vector) -> Vector: ...

class _ClassificationSummary(JavaWrapper):
@property
Expand Down Expand Up @@ -543,7 +543,7 @@ class RandomForestClassificationModel(
@property
def trees(self) -> List[DecisionTreeClassificationModel]: ...
def summary(self) -> RandomForestClassificationTrainingSummary: ...
def evaluate(self, dataset) -> RandomForestClassificationSummary: ...
def evaluate(self, dataset: DataFrame) -> RandomForestClassificationSummary: ...

class RandomForestClassificationSummary(_ClassificationSummary): ...
class RandomForestClassificationTrainingSummary(
Expand Down Expand Up @@ -891,7 +891,7 @@ class FMClassifier(
solver: str = ...,
thresholds: Optional[Any] = ...,
seed: Optional[Any] = ...,
): ...
) -> FMClassifier: ...
def setFactorSize(self, value: int) -> FMClassifier: ...
def setFitLinear(self, value: bool) -> FMClassifier: ...
def setMiniBatchFraction(self, value: float) -> FMClassifier: ...
Expand Down
10 changes: 8 additions & 2 deletions python/pyspark/ml/common.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
# specific language governing permissions and limitations
# under the License.

def callJavaFunc(sc, func, *args): ...
def inherit_doc(cls): ...
from typing import Any, TypeVar

import pyspark.context

C = TypeVar("C", bound=type)

def callJavaFunc(sc: pyspark.context.SparkContext, func: Any, *args: Any) -> Any: ...
def inherit_doc(cls: C) -> C: ...
24 changes: 13 additions & 11 deletions python/pyspark/ml/evaluation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ from pyspark.ml.param.shared import (
HasWeightCol,
)
from pyspark.ml.util import JavaMLReadable, JavaMLWritable
from pyspark.sql.dataframe import DataFrame

class Evaluator(Params, metaclass=abc.ABCMeta):
def evaluate(self, dataset, params: Optional[ParamMap] = ...) -> float: ...
def evaluate(
self, dataset: DataFrame, params: Optional[ParamMap] = ...
) -> float: ...
def isLargerBetter(self) -> bool: ...

class JavaEvaluator(JavaParams, Evaluator, metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -75,16 +78,15 @@ class BinaryClassificationEvaluator(
def setLabelCol(self, value: str) -> BinaryClassificationEvaluator: ...
def setRawPredictionCol(self, value: str) -> BinaryClassificationEvaluator: ...
def setWeightCol(self, value: str) -> BinaryClassificationEvaluator: ...

def setParams(
self,
*,
rawPredictionCol: str = ...,
labelCol: str = ...,
metricName: BinaryClassificationEvaluatorMetricType = ...,
weightCol: Optional[str] = ...,
numBins: int = ...
) -> BinaryClassificationEvaluator: ...
def setParams(
self,
*,
rawPredictionCol: str = ...,
labelCol: str = ...,
metricName: BinaryClassificationEvaluatorMetricType = ...,
weightCol: Optional[str] = ...,
numBins: int = ...
) -> BinaryClassificationEvaluator: ...

class RegressionEvaluator(
JavaEvaluator,
Expand Down
10 changes: 5 additions & 5 deletions python/pyspark/ml/feature.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class _LSHParams(HasInputCol, HasOutputCol):
def getNumHashTables(self) -> int: ...

class _LSH(Generic[JM], JavaEstimator[JM], _LSHParams, JavaMLReadable, JavaMLWritable):
def setNumHashTables(self: P, value) -> P: ...
def setInputCol(self: P, value) -> P: ...
def setOutputCol(self: P, value) -> P: ...
def setNumHashTables(self: P, value: int) -> P: ...
def setInputCol(self: P, value: str) -> P: ...
def setOutputCol(self: P, value: str) -> P: ...

class _LSHModel(JavaModel, _LSHParams):
def setInputCol(self: P, value: str) -> P: ...
Expand Down Expand Up @@ -1518,7 +1518,7 @@ class ChiSqSelector(
fpr: float = ...,
fdr: float = ...,
fwe: float = ...
): ...
) -> ChiSqSelector: ...
def setSelectorType(self, value: str) -> ChiSqSelector: ...
def setNumTopFeatures(self, value: int) -> ChiSqSelector: ...
def setPercentile(self, value: float) -> ChiSqSelector: ...
Expand Down Expand Up @@ -1615,7 +1615,7 @@ class VarianceThresholdSelector(
featuresCol: str = ...,
outputCol: Optional[str] = ...,
varianceThreshold: float = ...,
): ...
) -> VarianceThresholdSelector: ...
def setVarianceThreshold(self, value: float) -> VarianceThresholdSelector: ...
def setFeaturesCol(self, value: str) -> VarianceThresholdSelector: ...
def setOutputCol(self, value: str) -> VarianceThresholdSelector: ...
Expand Down
36 changes: 16 additions & 20 deletions python/pyspark/ml/linalg/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.

from typing import overload
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
from typing import Any, Dict, Iterable, List, NoReturn, Optional, Tuple, Type, Union

from pyspark.ml import linalg as newlinalg # noqa: F401
from pyspark.sql.types import StructType, UserDefinedType
Expand Down Expand Up @@ -45,7 +45,7 @@ class MatrixUDT(UserDefinedType):
@classmethod
def scalaUDT(cls) -> str: ...
def serialize(
self, obj
self, obj: Matrix
) -> Tuple[
int, int, int, Optional[List[int]], Optional[List[int]], List[float], bool
]: ...
Expand All @@ -64,9 +64,7 @@ class DenseVector(Vector):
def __init__(self, __arr: bytes) -> None: ...
@overload
def __init__(self, __arr: Iterable[float]) -> None: ...
@staticmethod
def parse(s) -> DenseVector: ...
def __reduce__(self) -> Tuple[type, bytes]: ...
def __reduce__(self) -> Tuple[Type[DenseVector], bytes]: ...
def numNonzeros(self) -> int: ...
def norm(self, p: Union[float, str]) -> float64: ...
def dot(self, other: Iterable[float]) -> float64: ...
Expand Down Expand Up @@ -112,16 +110,14 @@ class SparseVector(Vector):
def __init__(self, size: int, __map: Dict[int, float]) -> None: ...
def numNonzeros(self) -> int: ...
def norm(self, p: Union[float, str]) -> float64: ...
def __reduce__(self): ...
@staticmethod
def parse(s: str) -> SparseVector: ...
def __reduce__(self) -> Tuple[Type[SparseVector], Tuple[int, bytes, bytes]]: ...
def dot(self, other: Iterable[float]) -> float64: ...
def squared_distance(self, other: Iterable[float]) -> float64: ...
def toArray(self) -> ndarray: ...
def __len__(self) -> int: ...
def __eq__(self, other) -> bool: ...
def __eq__(self, other: Any) -> bool: ...
def __getitem__(self, index: int) -> float64: ...
def __ne__(self, other) -> bool: ...
def __ne__(self, other: Any) -> bool: ...
def __hash__(self) -> int: ...

class Vectors:
Expand All @@ -144,22 +140,20 @@ class Vectors:
def sparse(size: int, __map: Dict[int, float]) -> SparseVector: ...
@overload
@staticmethod
def dense(self, *elements: float) -> DenseVector: ...
def dense(*elements: float) -> DenseVector: ...
@overload
@staticmethod
def dense(self, __arr: bytes) -> DenseVector: ...
def dense(__arr: bytes) -> DenseVector: ...
@overload
@staticmethod
def dense(self, __arr: Iterable[float]) -> DenseVector: ...
def dense(__arr: Iterable[float]) -> DenseVector: ...
@staticmethod
def stringify(vector: Vector) -> str: ...
@staticmethod
def squared_distance(v1: Vector, v2: Vector) -> float64: ...
@staticmethod
def norm(vector: Vector, p: Union[float, str]) -> float64: ...
@staticmethod
def parse(s: str) -> Vector: ...
@staticmethod
def zeros(size: int) -> DenseVector: ...

class Matrix:
Expand All @@ -170,7 +164,7 @@ class Matrix:
def __init__(
self, numRows: int, numCols: int, isTransposed: bool = ...
) -> None: ...
def toArray(self): ...
def toArray(self) -> NoReturn: ...

class DenseMatrix(Matrix):
values: Any
Expand All @@ -186,11 +180,11 @@ class DenseMatrix(Matrix):
values: Iterable[float],
isTransposed: bool = ...,
) -> None: ...
def __reduce__(self) -> Tuple[type, Tuple[int, int, bytes, int]]: ...
def __reduce__(self) -> Tuple[Type[DenseMatrix], Tuple[int, int, bytes, int]]: ...
def toArray(self) -> ndarray: ...
def toSparse(self) -> SparseMatrix: ...
def __getitem__(self, indices: Tuple[int, int]) -> float64: ...
def __eq__(self, other) -> bool: ...
def __eq__(self, other: Any) -> bool: ...

class SparseMatrix(Matrix):
colPtrs: ndarray
Expand All @@ -216,11 +210,13 @@ class SparseMatrix(Matrix):
values: Iterable[float],
isTransposed: bool = ...,
) -> None: ...
def __reduce__(self) -> Tuple[type, Tuple[int, int, bytes, bytes, bytes, int]]: ...
def __reduce__(
self,
) -> Tuple[Type[SparseMatrix], Tuple[int, int, bytes, bytes, bytes, int]]: ...
def __getitem__(self, indices: Tuple[int, int]) -> float64: ...
def toArray(self) -> ndarray: ...
def toDense(self) -> DenseMatrix: ...
def __eq__(self, other) -> bool: ...
def __eq__(self, other: Any) -> bool: ...

class Matrices:
@overload
Expand Down
Loading