From cb43b2f20e21db25bb17f334bfa8f08a7292186d Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sat, 27 Feb 2016 17:14:07 -0500 Subject: [PATCH] COMPAT: older numpies compat on dtype upcasting, xref #10503 --- pandas/core/internals.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 253647e88c088..484cb6afa77b2 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -717,8 +717,23 @@ def _is_empty_indexer(indexer): block = block.convert(numeric=False) return block - except (ValueError, TypeError): + except ValueError: raise + except TypeError: + + # cast to the passed dtype if possible + # otherwise raise the original error + try: + # e.g. we are uint32 and our value is uint64 + # this is for compat with older numpies + block = self.make_block(transf(values.astype(value.dtype))) + return block.setitem(indexer=indexer, value=value, mgr=mgr) + + except: + pass + + raise + except Exception: pass