From fe367e097ab346f3c90e2d41cbb7d47a9b6df38e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 7 Mar 2020 10:26:12 -0800 Subject: [PATCH] CLN: avoid Block.get_values in io.sql --- pandas/io/sql.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 9a53e7cd241e1..560e7e4781cbb 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -705,8 +705,16 @@ def insert_data(self): else: # convert to microsecond resolution for datetime.datetime d = b.values.astype("M8[us]").astype(object) + elif b.is_timedelta: + # numpy converts this to an object array of integers, + # whereas b.astype(object).values would convert to + # object array of Timedeltas + d = b.values.astype(object) else: - d = np.array(b.get_values(), dtype=object) + # TODO(2DEA): astype-first can be avoided with 2D EAs + # astype on the block instead of values to ensure we + # get the right shape + d = b.astype(object).values # replace NaN with None if b._can_hold_na: