<s> import numpy as np <EOL> import xarray . ufuncs as xu <EOL> import xarray as xr <EOL> from . import TestCase <EOL> class TestOps ( TestCase ) : <EOL> def assertIdentical ( self , a , b ) : <EOL> assert type ( a ) is type ( b ) or ( float ( a ) == float ( b ) ) <EOL> try : <EOL> assert a . identical ( b ) , ( a , b ) <EOL> except AttributeError : <EOL> self . assertArrayEqual ( a , b ) <EOL> def test_unary ( self ) : <EOL> args = [ <NUM_LIT:0> , <EOL> np . zeros ( <NUM_LIT:2> ) , <EOL> xr . Variable ( [ '<STR_LIT:x>' ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) , <EOL> xr . DataArray ( [ <NUM_LIT:0> , <NUM_LIT:0> ] , dims = '<STR_LIT:x>' ) , <EOL> xr . Dataset ( { '<STR_LIT:y>' : ( '<STR_LIT:x>' , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) } ) ] <EOL> for a in args : <EOL> self . assertIdentical ( a + <NUM_LIT:1> , xu . cos ( a ) ) <EOL> def test_binary ( self ) : <EOL> args = [ <NUM_LIT:0> , <EOL> np . zeros ( <NUM_LIT:2> ) , <EOL> xr . Variable ( [ '<STR_LIT:x>' ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) , <EOL> xr . DataArray ( [ <NUM_LIT:0> , <NUM_LIT:0> ] , dims = '<STR_LIT:x>' ) , <EOL> xr . Dataset ( { '<STR_LIT:y>' : ( '<STR_LIT:x>' , [ <NUM_LIT:0> , <NUM_LIT:0> ] ) } ) ] <EOL> for n , t1 in enumerate ( args ) : <EOL> for t2 in args [ n : ] : <EOL> self . assertIdentical ( t2 + <NUM_LIT:1> , xu . maximum ( t1 , t2 + <NUM_LIT:1> ) ) <EOL> self . assertIdentical ( t2 + <NUM_LIT:1> , xu . maximum ( t2 , t1 + <NUM_LIT:1> ) ) <EOL> self . assertIdentical ( t2 + <NUM_LIT:1> , xu . maximum ( t1 + <NUM_LIT:1> , t2 ) ) <EOL> self . assertIdentical ( t2 + <NUM_LIT:1> , xu . maximum ( t2 + <NUM_LIT:1> , t1 ) ) <EOL> def test_groupby ( self ) : <EOL> ds = xr . Dataset ( { '<STR_LIT:a>' : ( '<STR_LIT:x>' , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) } , { '<STR_LIT:c>' : ( '<STR_LIT:x>' , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ) } ) <EOL> ds_grouped = ds . groupby ( '<STR_LIT:c>' ) <EOL> group_mean = ds_grouped . mean ( '<STR_LIT:x>' ) <EOL> arr_grouped = ds [ '<STR_LIT:a>' ] . groupby ( '<STR_LIT:c>' ) <EOL> self . assertIdentical ( ds , xu . maximum ( ds_grouped , group_mean ) ) <EOL> self . assertIdentical ( ds , xu . maximum ( group_mean , ds_grouped ) ) <EOL> self . assertIdentical ( ds , xu . maximum ( arr_grouped , group_mean ) ) <EOL> self . assertIdentical ( ds , xu . maximum ( group_mean , arr_grouped ) ) <EOL> self . assertIdentical ( ds , xu . maximum ( ds_grouped , group_mean [ '<STR_LIT:a>' ] ) ) <EOL> self . assertIdentical ( ds , xu . maximum ( group_mean [ '<STR_LIT:a>' ] , ds_grouped ) ) <EOL> self . assertIdentical ( ds . a , xu . maximum ( arr_grouped , group_mean . a ) ) <EOL> self . assertIdentical ( ds . a , xu . maximum ( group_mean . a , arr_grouped ) ) <EOL> with self . assertRaisesRegexp ( TypeError , '<STR_LIT>' ) : <EOL> xu . maximum ( ds . a . variable , ds_grouped ) </s>
