From b5fe3f79d755c722960412bac7a426e9f40aa751 Mon Sep 17 00:00:00 2001 From: yichen8 <43142019+yichen8@users.noreply.github.com> Date: Thu, 14 Feb 2019 21:17:05 +0800 Subject: [PATCH 1/2] fix the function `find_common_types` bug ` types[0]` can raise a KeyError when `types` is a `pd.Series` . see issue #25270 --- pandas/core/dtypes/cast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index f6561948df99a..2f957d1cab6cb 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1075,7 +1075,7 @@ def find_common_type(types): Parameters ---------- - types : list of dtypes + types : list_like Returns ------- @@ -1090,7 +1090,7 @@ def find_common_type(types): if len(types) == 0: raise ValueError('no types given') - first = types[0] + first = types[:1] # workaround for find_common_type([np.dtype('datetime64[ns]')] * 2) # => object From ccca752414a457e2d41f9d0c5569cacfa8feeff1 Mon Sep 17 00:00:00 2001 From: yichen8 <43142019+yichen8@users.noreply.github.com> Date: Sun, 17 Feb 2019 10:56:47 +0800 Subject: [PATCH 2/2] update find_common_type() statement about first. Last modification can't pass test, so fix it and now it can pass test. --- pandas/core/dtypes/cast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 2f957d1cab6cb..6c4a801155899 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1090,7 +1090,7 @@ def find_common_type(types): if len(types) == 0: raise ValueError('no types given') - first = types[:1] + first = [t for t in types][0] # workaround for find_common_type([np.dtype('datetime64[ns]')] * 2) # => object