@@ -1863,6 +1863,41 @@ def test_drop_index_labels(self):
18631863 ValueError , 'does not have coordinate labels' ):
18641864 data .drop (1 , 'y' )
18651865
1866+ def test_drop_dims (self ):
1867+ data = xr .Dataset ({'A' : (['x' , 'y' ], np .random .randn (2 , 3 )),
1868+ 'B' : ('x' , np .random .randn (2 )),
1869+ 'x' : ['a' , 'b' ], 'z' : np .pi })
1870+
1871+ actual = data .drop_dims ('x' )
1872+ expected = data .drop (['A' ,'B' ,'x' ])
1873+ assert_identical (expected , actual )
1874+
1875+ actual = data .drop_dims ('y' )
1876+ expected = data .drop ('A' )
1877+ assert_identical (expected , actual )
1878+
1879+ actual = data .drop_dims (['x' ,'y' ])
1880+ expected = data .drop (['A' ,'B' ,'x' ])
1881+ assert_identical (expected , actual )
1882+
1883+ actual = data .copy ()
1884+ actual .drop_dims ('y' , inplace = True )
1885+ expected = data .drop ('A' )
1886+ assert_identical (expected , actual )
1887+
1888+ actual = data .copy ()
1889+ actual .drop_dims ('x' , inplace = True )
1890+ expected = data .drop (['A' ,'B' ,'x' ])
1891+ assert_identical (expected , actual )
1892+
1893+ actual = data .copy ()
1894+ actual .drop_dims (['x' ,'y' ], inplace = True )
1895+ expected = data .drop (['A' ,'B' ,'x' ])
1896+ assert_identical (expected , actual )
1897+
1898+ with pytest .raises ((ValueError , KeyError )):
1899+ data .drop_dims ('z' ) # not a dimension
1900+
18661901 def test_copy (self ):
18671902 data = create_test_data ()
18681903
0 commit comments