comparison test_dataset.py @ 269:fdce496c3b56

deprecating __getitem__[fieldname] syntax
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 04 Jun 2008 19:04:40 -0400
parents 3f1cd8897fda
children 271a16d42072
comparison
equal deleted inserted replaced
268:3f1cd8897fda 269:fdce496c3b56
303 del ds2 303 del ds2
304 304
305 #ds[fieldname]# an iterable over the values of the field fieldname across 305 #ds[fieldname]# an iterable over the values of the field fieldname across
306 #the ds (the iterable is obtained by default by calling valuesVStack 306 #the ds (the iterable is obtained by default by calling valuesVStack
307 #over the values for individual examples). 307 #over the values for individual examples).
308 assert have_raised("ds['h']") # h is not defined... 308 if 0:
309 assert have_raised("ds[['x']]") # bad syntax 309 assert have_raised("ds['h']") # h is not defined...
310 assert not have_raised("var['ds']['x']",ds=ds) 310 assert have_raised("ds[['x']]") # bad syntax
311 isinstance(ds['x'],DataSetFields) 311 assert not have_raised("var['ds']['x']",ds=ds)
312 ds2=ds['x'] 312 isinstance(ds['x'],DataSetFields)
313 assert len(ds['x'])==10 313 ds2=ds['x']
314 assert len(ds['y'])==10 314 assert len(ds['x'])==10
315 assert len(ds['z'])==10 315 assert len(ds['y'])==10
316 i=0 316 assert len(ds['z'])==10
317 for example in ds['x']: 317 i=0
318 assert (example==array[i][:3]).all() 318 for example in ds['x']:
319 i+=1 319 assert (example==array[i][:3]).all()
320 assert i==len(ds) 320 i+=1
321 i=0 321 assert i==len(ds)
322 for example in ds['y']: 322 i=0
323 assert (example==array[i][3]).all() 323 for example in ds['y']:
324 i+=1 324 assert (example==array[i][3]).all()
325 assert i==len(ds) 325 i+=1
326 i=0 326 assert i==len(ds)
327 for example in ds['z']: 327 i=0
328 assert (example==array[i,0:3:2]).all() 328 for example in ds['z']:
329 i+=1 329 assert (example==array[i,0:3:2]).all()
330 assert i==len(ds) 330 i+=1
331 del ds2,i 331 assert i==len(ds)
332 332 del ds2,i
333 #ds.<property># returns the value of a property associated with 333 else:
334 #the name <property>. The following properties should be supported: 334 print 'warning: ds[fieldname] is deprecated... Fred could you fix this test?'
335 # - 'description': a textual description or name for the ds 335
336 # - 'fieldtypes': a list of types (one per field) 336 #ds.<property># returns the value of a property associated with
337 337 #the name <property>. The following properties should be supported:
338 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#???? 338 # - 'description': a textual description or name for the ds
339 #assert hstack([ds('x','y'),ds('z')])==ds 339 # - 'fieldtypes': a list of types (one per field)
340 #hstack([ds('z','y'),ds('x')])==ds 340
341 #* ds1 | ds2 | ds3 == ds.hstack([ds1,ds2,ds3])#????
342 #assert hstack([ds('x','y'),ds('z')])==ds
343 #hstack([ds('z','y'),ds('x')])==ds
341 assert have_raised2(hstack,[ds('x'),ds('x')]) 344 assert have_raised2(hstack,[ds('x'),ds('x')])
342 assert have_raised2(hstack,[ds('y','x'),ds('x')]) 345 assert have_raised2(hstack,[ds('y','x'),ds('x')])
343 assert not have_raised2(hstack,[ds('x'),ds('y')]) 346 assert not have_raised2(hstack,[ds('x'),ds('y')])
344 347
345 # i=0 348 # i=0
346 # for example in hstack([ds('x'),ds('y'),ds('z')]): 349 # for example in hstack([ds('x'),ds('y'),ds('z')]):
347 # example==ds[i] 350 # example==ds[i]
348 # i+=1 351 # i+=1
349 # del i,example 352 # del i,example
350 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#???? 353 #* ds1 & ds2 & ds3 == ds.vstack([ds1,ds2,ds3])#????
351 354
352 def test_fields_fct(ds): 355 def test_fields_fct(ds):
353 #@todo, fill correctly 356 #@todo, fill correctly
354 assert len(ds.fields())==3 357 assert len(ds.fields())==3
355 i=0 358 i=0