I have a class that takes a Spark DataFrame
and does some processing to it. Here is the code:
for column in self.sdf.columns:
if column not in self.__columns:
row = [column]
row += '--' * 9
column_table.append(row)
I have this code inside constructor of my class:
self.sdf: Optional[SparkDataFrame] = None
Here sdf
is set dynamically during execution of my class and then the for loop mentioned above will run. __columns
is a dictionary which is supposed to have all the columns of sdf. I found no errors in the code when it ran. But when I type checked my code with mypy
, it showed an error on the first line of for loop:
error: Item "None" of "Optional[Any]" has no attribute "columns"
I understand that initially sdf will be None
. But should I consider this a serious error? Is there are any workarounds for this?