Skip to content

Commit

Permalink
rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jana-starkova committed Aug 2, 2023
1 parent bb871e9 commit 806756d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion tests/_schema/test_get_schema_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pyspark.sql.types import IntegerType, StringType

from typedspark import Column, DayTimeIntervalType, IntervalType, Schema

from typedspark._schema.get_schema_definition import _replace_literal, _replace_literals


Expand Down
9 changes: 5 additions & 4 deletions typedspark/_schema/get_schema_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def _build_schema_definition_string(
else:
lines += ' """Add documentation here."""\n\n'

for col_name, col in get_type_hints(schema).items():
for col_name, col_object in get_type_hints(schema).items():
typehint = (
str(col)
str(col_object)
.replace("typedspark._core.column.", "")
.replace("typedspark._core.datatypes.", "")
.replace("typedspark._schema.schema.", "")
Expand All @@ -62,17 +62,18 @@ def _build_schema_definition_string(
typehint, replace_literals_in=DayTimeIntervalType, replace_literals_by=IntervalType
)
if include_documentation:
col_annotated_start = f" {col_name}: Annotated[{typehint}, "
if col_name in schema.__annotations__:
if (
hasattr(schema.__annotations__[col_name], "__metadata__")
and schema.__annotations__[col_name].__metadata__ is not None
):
lines += (
f" {col_name}: Annotated[{typehint}, "
col_annotated_start
+ f'ColumnMeta(comment="{schema.__annotations__[col_name].__metadata__[0]}")]\n'
)
else:
lines += f' {col_name}: Annotated[{typehint}, ColumnMeta(comment="")]\n'
lines += col_annotated_start + 'ColumnMeta(comment="")]\n'
else:
lines += f" {col_name}: {typehint}\n"

Expand Down

0 comments on commit 806756d

Please sign in to comment.