@@ -41,10 +41,10 @@ def get_table_python_types(self, database, table):
4141 :return: A dictionary as {"col name": "col python type"}
4242 """
4343 dtypes = self .get_table_athena_types (database = database , table = table )
44- return {k : Glue ._type_athena2python (v ) for k , v in dtypes .items ()}
44+ return {k : Glue .type_athena2python (v ) for k , v in dtypes .items ()}
4545
4646 @staticmethod
47- def _type_pandas2athena (dtype ):
47+ def type_pandas2athena (dtype ):
4848 dtype = dtype .lower ()
4949 if dtype == "int32" :
5050 return "int"
@@ -64,7 +64,7 @@ def _type_pandas2athena(dtype):
6464 raise UnsupportedType (f"Unsupported Pandas type: { dtype } " )
6565
6666 @staticmethod
67- def _type_athena2python (dtype ):
67+ def type_athena2python (dtype ):
6868 dtype = dtype .lower ()
6969 if dtype in ["int" , "integer" , "bigint" , "smallint" , "tinyint" ]:
7070 return int
@@ -81,6 +81,24 @@ def _type_athena2python(dtype):
8181 else :
8282 raise UnsupportedType (f"Unsupported Athena type: { dtype } " )
8383
84+ @staticmethod
85+ def type_python2athena (python_type ):
86+ python_type = str (python_type )
87+ if python_type == "<class 'int'>" :
88+ return "bigint"
89+ elif python_type == "<class 'float'>" :
90+ return "double"
91+ elif python_type == "<class 'boll'>" :
92+ return "boolean"
93+ elif python_type == "<class 'str'>" :
94+ return "string"
95+ elif python_type == "<class 'datetime.datetime'>" :
96+ return "timestamp"
97+ elif python_type == "<class 'datetime.date'>" :
98+ return "date"
99+ else :
100+ raise UnsupportedType (f"Unsupported Python type: { python_type } " )
101+
84102 def metadata_to_glue (self ,
85103 dataframe ,
86104 path ,
@@ -190,7 +208,7 @@ def _build_schema(dataframe,
190208 dataframe .index .name = "index"
191209 dtype = str (dataframe .index .dtype )
192210 if name not in partition_cols :
193- athena_type = Glue ._type_pandas2athena (dtype )
211+ athena_type = Glue .type_pandas2athena (dtype )
194212 schema_built .append ((name , athena_type ))
195213 for col in dataframe .columns :
196214 name = str (col )
@@ -199,7 +217,7 @@ def _build_schema(dataframe,
199217 else :
200218 dtype = str (dataframe [name ].dtype )
201219 if name not in partition_cols :
202- athena_type = Glue ._type_pandas2athena (dtype )
220+ athena_type = Glue .type_pandas2athena (dtype )
203221 schema_built .append ((name , athena_type ))
204222 logger .debug (f"schema_built:\n { schema_built } " )
205223 return schema_built
0 commit comments