Skip to content

Commit 0144818

Browse files
ueshinHyukjinKwon
authored andcommitted
[SPARK-36985][PYTHON] Fix future typing errors in pyspark.pandas
### What changes were proposed in this pull request? Fix future typing errors in pyspark.pandas detected with mypy master. ### Why are the changes needed? The following problems are detected on master with mypy master. ``` pyspark/pandas/indexes/base.py:184: error: Incompatible types in assignment (expression has type "CategoricalIndex", variable has type "MultiIndex") [assignment] pyspark/pandas/indexes/base.py:188: error: Incompatible types in assignment (expression has type "Int64Index", variable has type "MultiIndex") [assignment] pyspark/pandas/indexes/base.py:192: error: Incompatible types in assignment (expression has type "Float64Index", variable has type "MultiIndex") [assignment] pyspark/pandas/indexes/base.py:197: error: Incompatible types in assignment (expression has type "DatetimeIndex", variable has type "MultiIndex") [assignment] pyspark/pandas/indexes/base.py:199: error: Incompatible types in assignment (expression has type "Index", variable has type "MultiIndex") [assignment] pyspark/pandas/indexes/base.py:201: error: "MultiIndex" has no attribute "_anchor" [attr-defined] ``` The complaints are legitimate now and we should fix them. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manually checked with the latest mypy master python/mypy@066da4d. Closes #34266 from ueshin/issues/SPARK-36985/mypy0.920. Authored-by: Takuya UESHIN <ueshin@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent 973f04e commit 0144818

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • python/pyspark/pandas/indexes

python/pyspark/pandas/indexes/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def _new_instance(anchor: DataFrame) -> "Index":
178178
from pyspark.pandas.indexes.multi import MultiIndex
179179
from pyspark.pandas.indexes.numeric import Float64Index, Int64Index
180180

181+
instance: Index
181182
if anchor._internal.index_level > 1:
182183
instance = object.__new__(MultiIndex)
183184
elif isinstance(anchor._internal.index_fields[0].dtype, CategoricalDtype):
@@ -198,7 +199,7 @@ def _new_instance(anchor: DataFrame) -> "Index":
198199
else:
199200
instance = object.__new__(Index)
200201

201-
instance._anchor = anchor
202+
instance._anchor = anchor # type: ignore[attr-defined]
202203
return instance
203204

204205
@property

0 commit comments

Comments
 (0)