From bd45d391bce7fa2310c7dbe4646d4b1666783332 Mon Sep 17 00:00:00 2001 From: y-p Date: Sun, 11 Nov 2012 02:43:59 +0200 Subject: [PATCH] ENH: warn user when invoking to_dict() on df with non-unique columns --- pandas/core/frame.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e4e9705e562d0..05d3713375481 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -837,6 +837,10 @@ def to_dict(self, outtype='dict'): ------- result : dict like {column -> {index -> value}} """ + import warnings + if not self.columns.is_unique: + warnings.warn("DataFrame columns are not unique, some " + "columns will be omitted.",UserWarning) if outtype.lower().startswith('d'): return dict((k, v.to_dict()) for k, v in self.iteritems()) elif outtype.lower().startswith('l'):