File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,8 @@ pandas 0.10.1
101
101
- Fix setitem on a Series with a boolean key and a non-scalar as value (GH2686 _)
102
102
- Box datetime64 values in Series.apply/map (GH2627 _, GH2689 _)
103
103
- Upconvert datetime + datetime64 values when concatenating frames (GH2624 _)
104
+ - Raise a more helpful error message in merge operations when one DataFrame
105
+ has duplicate columns (GH2649 _)
104
106
105
107
**API Changes **
106
108
@@ -124,10 +126,11 @@ pandas 0.10.1
124
126
.. _GH2624 : https://github.com/pydata/pandas/issues/2624
125
127
.. _GH2625 : https://github.com/pydata/pandas/issues/2625
126
128
.. _GH2627 : https://github.com/pydata/pandas/issues/2627
127
- .. _GH2643 : https://github.com/pydata/pandas/issues/2643
128
129
.. _GH2631 : https://github.com/pydata/pandas/issues/2631
129
130
.. _GH2633 : https://github.com/pydata/pandas/issues/2633
130
131
.. _GH2637 : https://github.com/pydata/pandas/issues/2637
132
+ .. _GH2643 : https://github.com/pydata/pandas/issues/2643
133
+ .. _GH2649 : https://github.com/pydata/pandas/issues/2649
131
134
.. _GH2668 : https://github.com/pydata/pandas/issues/2668
132
135
.. _GH2689 : https://github.com/pydata/pandas/issues/2689
133
136
.. _GH2690 : https://github.com/pydata/pandas/issues/2690
Original file line number Diff line number Diff line change @@ -378,6 +378,14 @@ def _validate_specification(self):
378
378
if self .left_on is None :
379
379
raise MergeError ('Must pass left_on or left_index=True' )
380
380
else :
381
+ if not self .left .columns .is_unique :
382
+ raise MergeError ("Left data columns not unique: %s"
383
+ % repr (self .left .columns ))
384
+
385
+ if not self .right .columns .is_unique :
386
+ raise MergeError ("Right data columns not unique: %s"
387
+ % repr (self .right .columns ))
388
+
381
389
# use the common columns
382
390
common_cols = self .left .columns .intersection (
383
391
self .right .columns )
Original file line number Diff line number Diff line change @@ -713,6 +713,19 @@ def test_merge_nosort(self):
713
713
714
714
self .assert_ ((df .var3 .unique () == result .var3 .unique ()).all ())
715
715
716
+ def test_overlapping_columns_error_message (self ):
717
+ # #2649
718
+ df = DataFrame ({'key' : [1 , 2 , 3 ],
719
+ 'v1' : [4 , 5 , 6 ],
720
+ 'v2' : [7 , 8 , 9 ]})
721
+ df2 = DataFrame ({'key' : [1 , 2 , 3 ],
722
+ 'v1' : [4 , 5 , 6 ],
723
+ 'v2' : [7 , 8 , 9 ]})
724
+
725
+ df .columns = ['key' , 'foo' , 'foo' ]
726
+ df2 .columns = ['key' , 'bar' , 'bar' ]
727
+
728
+ self .assertRaises (Exception , merge , df , df2 )
716
729
717
730
def _check_merge (x , y ):
718
731
for how in ['inner' , 'left' , 'outer' ]:
You can’t perform that action at this time.
0 commit comments