Skip to content

Commit

Permalink
fix(snowflake): convert arrays, maps and structs using the base class…
Browse files Browse the repository at this point in the history
… implementation
  • Loading branch information
cpcloud committed Dec 18, 2023
1 parent 758ec25 commit f361891
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ibis/backends/snowflake/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@


class SnowflakePandasData(PandasData):
@classmethod
def convert_JSON(cls, s, dtype, pandas_type):
converter = cls.convert_JSON_element(dtype)
return s.map(converter, na_action="ignore").astype("object")

convert_Struct = convert_Map = convert_JSON

@classmethod
def convert_Timestamp_element(cls, dtype):
return datetime.datetime.fromisoformat
Expand All @@ -33,11 +26,25 @@ def convert_Date_element(cls, dtype):
def convert_Time_element(cls, dtype):
return datetime.time.fromisoformat

@classmethod
def convert_JSON(cls, s, dtype, pandas_type):
converter = cls.convert_JSON_element(dtype)
return s.map(converter, na_action="ignore").astype("object")

@classmethod
def convert_Array(cls, s, dtype, pandas_type):
raw_json_objects = cls.convert_JSON(s, dtype, pandas_type)
converter = cls.get_element_converter(dtype.value_type)
return raw_json_objects.map(converter, na_action="ignore")
return super().convert_Array(raw_json_objects, dtype, pandas_type)

@classmethod
def convert_Map(cls, s, dtype, pandas_type):
raw_json_objects = cls.convert_JSON(s, dtype, pandas_type)
return super().convert_Map(raw_json_objects, dtype, pandas_type)

@classmethod
def convert_Struct(cls, s, dtype, pandas_type):
raw_json_objects = cls.convert_JSON(s, dtype, pandas_type)
return super().convert_Struct(raw_json_objects, dtype, pandas_type)


class SnowflakePyArrowData(PyArrowData):
Expand Down

0 comments on commit f361891

Please sign in to comment.