Skip to content
Prev Previous commit
Next Next commit
Cast dtype to dict
  • Loading branch information
avinashpancham committed Dec 28, 2020
commit 2c70647dd470fa7b68ef21ce6559c5aa16c4b4d2
11 changes: 7 additions & 4 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import date, datetime, time
from functools import partial
import re
from typing import Any, Dict, Iterator, List, Optional, Sequence, Union, overload
from typing import Any, Dict, Iterator, List, Optional, Sequence, Union, cast, overload
import warnings

import numpy as np
Expand Down Expand Up @@ -1493,10 +1493,13 @@ def to_sql(

.. versionadded:: 0.24.0
"""
if dtype and not is_dict_like(dtype):
dtype = {col_name: dtype for col_name in frame}
if dtype is not None:
if not is_dict_like(dtype):
dtype = {col_name: dtype for col_name in frame}
else:
dtype = cast(dict, dtype)

if dtype is not None and isinstance(dtype, dict):
if dtype:
from sqlalchemy.types import TypeEngine, to_instance

for col, my_type in dtype.items():
Expand Down