Skip to content

Commit

Permalink
merge main and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jrose committed Dec 17, 2024
1 parent a787e74 commit b32806f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/snowflake/snowpark/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ def __init__(
)
else:
self.structured = structured or False

self.fields = []
for field in fields or []:
self.add(field)

Expand Down
6 changes: 3 additions & 3 deletions tests/integ/scala/test_datatype_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,9 @@ def test_structured_dtypes_cast(structured_type_session, structured_type_support
pytest.skip("Test requires structured type support.")
expected_semi_schema = StructType(
[
StructField("ARR", ArrayType(StringType()), nullable=True),
StructField("MAP", MapType(StringType(), StringType()), nullable=True),
StructField("OBJ", MapType(StringType(), StringType()), nullable=True),
StructField("ARR", ArrayType(), nullable=True),
StructField("MAP", MapType(), nullable=True),
StructField("OBJ", MapType(), nullable=True),
]
)
expected_structured_schema = StructType(
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_datatype_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,17 @@ def test_to_sql():
assert (
to_sql([1, "2", 3.5], ArrayType()) == "PARSE_JSON('[1, \"2\", 3.5]') :: ARRAY"
)
assert (
to_sql([1, 2, 3], ArrayType(IntegerType(), structured=True))
== "PARSE_JSON('[1, 2, 3]') :: ARRAY(INT)"
)
assert (
to_sql({"'": '"'}, MapType()) == 'PARSE_JSON(\'{"\'\'": "\\\\""}\') :: OBJECT'
)
assert (
to_sql({"'": '"'}, MapType(StringType(), structured=True))
== 'PARSE_JSON(\'{"\'\'": "\\\\""}\') :: MAP(STRING, STRING)'
)
assert to_sql([{1: 2}], ArrayType()) == "PARSE_JSON('[{\"1\": 2}]') :: ARRAY"
assert to_sql({1: [2]}, MapType()) == "PARSE_JSON('{\"1\": [2]}') :: OBJECT"

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ def {func_name}(x, y {datatype_str} = {annotated_value}) -> None:
@pytest.mark.parametrize(
"value_str,datatype,expected_value",
[
(None, None, None),
("1", IntegerType(), 1),
("True", BooleanType(), True),
("1.0", FloatType(), 1.0),
Expand Down

0 comments on commit b32806f

Please sign in to comment.