@@ -1066,20 +1066,29 @@ def test_align(self):
10661066 align (left , right , foo = 'bar' )
10671067
10681068 def test_align_exclude (self ):
1069- x = Dataset ({'foo' : DataArray ([[1 , 2 ],[3 , 4 ]], dims = ['x' , 'y' ], coords = {'x' : [1 , 2 ], 'y' : [3 , 4 ]})})
1070- y = Dataset ({'bar' : DataArray ([[1 , 2 ],[3 , 4 ]], dims = ['x' , 'y' ], coords = {'x' : [1 , 3 ], 'y' : [5 , 6 ]})})
1069+ x = Dataset ({'foo' : DataArray ([[1 , 2 ],[3 , 4 ]], dims = ['x' , 'y' ],
1070+ coords = {'x' : [1 , 2 ], 'y' : [3 , 4 ]})})
1071+ y = Dataset ({'bar' : DataArray ([[1 , 2 ],[3 , 4 ]], dims = ['x' , 'y' ],
1072+ coords = {'x' : [1 , 3 ], 'y' : [5 , 6 ]})})
10711073 x2 , y2 = align (x , y , exclude = ['y' ], join = 'outer' )
10721074
1073- expected_x2 = Dataset ({'foo' : DataArray ([[1 , 2 ], [3 , 4 ], [np .nan , np .nan ]], dims = ['x' , 'y' ], coords = {'x' : [1 , 2 , 3 ], 'y' : [3 , 4 ]})})
1074- expected_y2 = Dataset ({'bar' : DataArray ([[1 , 2 ], [np .nan , np .nan ], [3 , 4 ]], dims = ['x' , 'y' ], coords = {'x' : [1 , 2 , 3 ], 'y' : [5 , 6 ]})})
1075+ expected_x2 = Dataset (
1076+ {'foo' : DataArray ([[1 , 2 ], [3 , 4 ], [np .nan , np .nan ]],
1077+ dims = ['x' , 'y' ],
1078+ coords = {'x' : [1 , 2 , 3 ], 'y' : [3 , 4 ]})})
1079+ expected_y2 = Dataset (
1080+ {'bar' : DataArray ([[1 , 2 ], [np .nan , np .nan ], [3 , 4 ]],
1081+ dims = ['x' , 'y' ],
1082+ coords = {'x' : [1 , 2 , 3 ], 'y' : [5 , 6 ]})})
10751083 self .assertDatasetIdentical (expected_x2 , x2 )
10761084 self .assertDatasetIdentical (expected_y2 , y2 )
10771085
10781086 def test_align_nocopy (self ):
10791087 x = Dataset ({'foo' : DataArray ([1 , 2 , 3 ], coords = {'x' : [1 , 2 , 3 ]})})
10801088 y = Dataset ({'foo' : DataArray ([1 , 2 ], coords = {'x' : [1 , 2 ]})})
10811089 expected_x2 = x
1082- expected_y2 = Dataset ({'foo' : DataArray ([1 , 2 , np .nan ], coords = {'x' : [1 , 2 , 3 ]})})
1090+ expected_y2 = Dataset ({'foo' : DataArray ([1 , 2 , np .nan ],
1091+ coords = {'x' : [1 , 2 , 3 ]})})
10831092
10841093 x2 , y2 = align (x , y , copy = False , join = 'outer' )
10851094 self .assertDatasetIdentical (expected_x2 , x2 )
@@ -1097,6 +1106,15 @@ def test_align_indexes(self):
10971106 expected_x2 = Dataset ({'foo' : DataArray ([2 , 3 , 1 ], coords = {'x' : [2 , 3 , 1 ]})})
10981107 self .assertDatasetIdentical (expected_x2 , x2 )
10991108
1109+ def test_align_non_unique (self ):
1110+ x = Dataset ({'foo' : ('x' , [3 , 4 , 5 ]), 'x' : [0 , 0 , 1 ]})
1111+ x1 , x2 = align (x , x )
1112+ assert x1 .identical (x ) and x2 .identical (x )
1113+
1114+ y = Dataset ({'bar' : ('x' , [6 , 7 ]), 'x' : [0 , 1 ]})
1115+ with self .assertRaisesRegexp (ValueError , 'cannot reindex or align' ):
1116+ align (x , y )
1117+
11001118 def test_broadcast (self ):
11011119 ds = Dataset ({'foo' : 0 , 'bar' : ('x' , [1 ]), 'baz' : ('y' , [2 , 3 ])},
11021120 {'c' : ('x' , [4 ])})
@@ -1573,7 +1591,7 @@ def test_assign(self):
15731591 expected = expected .set_coords ('c' )
15741592 self .assertDatasetIdentical (actual , expected )
15751593
1576- def test_setitem_non_unique_index (self ):
1594+ def test_setitem_original_non_unique_index (self ):
15771595 # regression test for GH943
15781596 original = Dataset ({'data' : ('x' , np .arange (5 ))},
15791597 coords = {'x' : [0 , 1 , 2 , 0 , 1 ]})
@@ -1591,6 +1609,17 @@ def test_setitem_non_unique_index(self):
15911609 actual .coords ['x' ] = list (range (5 ))
15921610 self .assertDatasetIdentical (actual , expected )
15931611
1612+ def test_setitem_both_non_unique_index (self ):
1613+ # regression test for GH956
1614+ names = ['joaquin' , 'manolo' , 'joaquin' ]
1615+ values = np .random .randint (0 , 256 , (3 , 4 , 4 ))
1616+ array = DataArray (values , dims = ['name' , 'row' , 'column' ],
1617+ coords = [names , range (4 ), range (4 )])
1618+ expected = Dataset ({'first' : array , 'second' : array })
1619+ actual = array .rename ('first' ).to_dataset ()
1620+ actual ['second' ] = array
1621+ self .assertDatasetIdentical (expected , actual )
1622+
15941623 def test_delitem (self ):
15951624 data = create_test_data ()
15961625 all_items = set (data )
0 commit comments