def test_Query_datetime1(self): d = cf.Data([[1., 5.], [6, 2]], 'days since 2000-12-29 21:00:00', calendar='standard') message = 'Diff =' + str( (d - cf.Data(cf.dt('2001-01-03 21:00:00', calendar='standard'))).array) self.assertTrue((d == cf.eq(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, True], [False, False]]), verbose=2), message) self.assertTrue((d == cf.ne(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, False], [True, True]])), message) self.assertTrue((d == cf.ge(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, True], [True, False]])), message) self.assertTrue((d == cf.gt(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, False], [True, False]])), message) self.assertTrue((d == cf.le(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, True], [False, True]])), message) self.assertTrue((d == cf.lt(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, False], [False, True]])), message) self.assertTrue((d == cf.wi(cf.dt('2000-12-31 21:00:00'), cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, True], [False, True]])), message) self.assertTrue((d == cf.wo(cf.dt('2000-12-31 21:00:00'), cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, False], [True, False]])), message) self.assertTrue((d == cf.set([ cf.dt('2000-12-31 21:00:00'), cf.dt('2001-01-03 21:00:00') ])).equals(cf.Data([[False, True], [False, True]])), message) _ = cf.seasons() [ cf.seasons(n, start) for n in [1, 2, 3, 4, 6, 12] for start in range(1, 13) ] with self.assertRaises(Exception): cf.seasons(13) with self.assertRaises(Exception): cf.seasons(start=8.456) _ = cf.mam() _ = cf.djf() _ = cf.jja() _ = cf.son()
def test_FieldList_select_by_construct(self): if self.test_only and inspect.stack()[0][3] not in self.test_only: return f = cf.read([self.filename, self.filename2]) g = f.select_by_construct() self.assertEqual(len(g), 2) g = f.select_by_construct('latitude') self.assertEqual(len(g), 2) g = f.select_by_construct('latitude', 'longitude') self.assertEqual(len(g), 2) g = f.select_by_construct('latitude', 'time') self.assertEqual(len(g), 1) g = f.select_by_construct('latitude', 'time', OR=False) self.assertEqual(len(g), 1) g = f.select_by_construct('latitude', 'time', OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(0)) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01'))) self.assertEqual(len(g), 1) g = f.select_by_construct(longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct('longitude', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct('latitude', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct('time', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct('time', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=False) self.assertEqual(len(g), 1) g = f.select_by_construct('time', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=False) self.assertEqual(len(g), 1) g = f.select_by_construct('qwerty') self.assertEqual(len(g), 0) g = f.select_by_construct('qwerty', 'latitude') self.assertEqual(len(g), 0) g = f.select_by_construct('qwerty', 'latitude', OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct('qwerty', 'time', 'longitude') self.assertEqual(len(g), 0) g = f.select_by_construct('qwerty', 'time', 'longitude', OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(70)) self.assertEqual(len(g), 1) g = f.select_by_construct(longitude=cf.gt(0), time=cf.le(cf.dt('1999-12-01'))) self.assertEqual(len(g), 0)
def test_Query_evaluate(self): for x in (5, cf.Data(5, 'kg m-2'), cf.Data([5], 'kg m-2 s-1')): self.assertEqual(x, cf.eq(5)) self.assertEqual(x, cf.lt(8)) self.assertEqual(x, cf.le(8)) self.assertEqual(x, cf.gt(3)) self.assertEqual(x, cf.ge(3)) self.assertEqual(x, cf.wi(3, 8)) self.assertEqual(x, cf.wo(8, 11)) self.assertEqual(x, cf.set([3, 5, 8])) self.assertEqual(cf.eq(5), x) self.assertEqual(cf.lt(8), x) self.assertEqual(cf.le(8), x) self.assertEqual(cf.gt(3), x) self.assertEqual(cf.ge(3), x) self.assertEqual(cf.wi(3, 8), x) self.assertEqual(cf.wo(8, 11), x) self.assertEqual(cf.set([3, 5, 8]), x) self.assertNotEqual(x, cf.eq(8)) self.assertNotEqual(x, cf.lt(3)) self.assertNotEqual(x, cf.le(3)) self.assertNotEqual(x, cf.gt(8)) self.assertNotEqual(x, cf.ge(8)) self.assertNotEqual(x, cf.wi(8, 11)) self.assertNotEqual(x, cf.wo(3, 8)) self.assertNotEqual(x, cf.set([3, 8, 11])) # Test that the evaluation is commutative i.e. A == B # means B == A self.assertNotEqual(x, cf.eq(8)) self.assertNotEqual(x, cf.lt(3)) self.assertNotEqual(x, cf.le(3)) self.assertNotEqual(x, cf.gt(8)) self.assertNotEqual(x, cf.ge(8)) self.assertNotEqual(x, cf.wi(8, 11)) self.assertNotEqual(x, cf.wo(3, 8)) self.assertNotEqual(x, cf.set([3, 8, 11])) self.assertNotEqual(cf.eq(8), x) self.assertNotEqual(cf.lt(3), x) self.assertNotEqual(cf.le(3), x) self.assertNotEqual(cf.gt(8), x) self.assertNotEqual(cf.ge(8), x) self.assertNotEqual(cf.wi(8, 11), x) self.assertNotEqual(cf.wo(3, 8), x) self.assertNotEqual(cf.set([3, 8, 11]), x) # --- End: for c = cf.wi(2, 4) d = cf.wi(6, 8) e = d | c self.assertTrue(c.evaluate(3)) self.assertFalse(c.evaluate(5)) self.assertTrue(e.evaluate(3)) self.assertTrue(e.evaluate(7)) self.assertFalse(e.evaluate(5)) self.assertEqual(3, c) self.assertNotEqual(5, c) self.assertEqual(c, 3) self.assertNotEqual(c, 5) self.assertEqual(3, e) self.assertEqual(7, e) self.assertNotEqual(5, e) self.assertEqual(e, 3) self.assertEqual(e, 7) self.assertNotEqual(e, 5) x = 'qwerty' self.assertEqual(x, cf.eq('qwerty')) self.assertEqual(x, cf.eq(re.compile('^qwerty$'))) self.assertEqual(x, cf.eq(re.compile('qwe'))) self.assertEqual(x, cf.eq(re.compile('qwe.*'))) self.assertEqual(x, cf.eq(re.compile('.*qwe'))) self.assertEqual(x, cf.eq(re.compile('.*rty'))) self.assertEqual(x, cf.eq(re.compile('.*rty$'))) self.assertEqual(x, cf.eq(re.compile('^.*rty$'))) self.assertEqual(x, cf.eq(re.compile('rty$'))) self.assertNotEqual(x, cf.eq('QWERTY')) self.assertNotEqual(x, cf.eq(re.compile('QWERTY'))) self.assertNotEqual(x, cf.eq(re.compile('^QWERTY$'))) self.assertNotEqual(x, cf.eq(re.compile('QWE'))) self.assertNotEqual(x, cf.eq(re.compile('QWE.*'))) self.assertNotEqual(x, cf.eq(re.compile('.*QWE'))) self.assertNotEqual(x, cf.eq(re.compile('.*RTY'))) self.assertNotEqual(x, cf.eq(re.compile('.*RTY$'))) self.assertNotEqual(x, cf.eq(re.compile('^.*RTY$')))
def test_Query_dteq_dtne_dtge_dtgt_dtle_dtlt(self): d = cf.Data([[1., 5.], [6, 2]], 'days since 2000-12-29 21:00:00') message = 'Diff =' + str((d-cf.Data( cf.dt('2001-01-03 21:00:00', calendar='standard'))).array) self.assertTrue( (d == cf.eq(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, True], [False, False]])), message ) self.assertTrue( (d == cf.ne(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, False], [True, True]])), message ) self.assertTrue( (d == cf.ge(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, True], [True, False]])), message ) self.assertTrue( (d == cf.gt(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[False, False], [True, False]])), message ) self.assertTrue( (d == cf.le(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, True], [False, True]])), message ) self.assertTrue( (d == cf.lt(cf.dt('2001-01-03 21:00:00'))).equals( cf.Data([[True, False], [False, True]])), message ) self.assertTrue( (d == cf.eq(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[False, True], [False, False]])), message ) self.assertTrue( (d == cf.ne(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[True, False], [True, True]])), message ) self.assertTrue( (d == cf.ge(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[False, True], [True, False]])), message ) self.assertTrue( (d == cf.gt(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[False, False], [True, False]])), message ) self.assertTrue( (d == cf.le(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[True, True], [False, True]])), message ) self.assertTrue( (d == cf.lt(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[True, False], [False, True]])), message ) d = cf.dt(2002, 6, 16) self.assertEqual(cf.eq(cf.dt(2002, 6, 16)), d) self.assertNotEqual(cf.eq(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.eq(cf.dt('2100-1-1')), d) self.assertNotEqual( cf.eq(cf.dt('2001-1-1')) & cf.eq(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertEqual(cf.ge(cf.dt(1990, 1, 1)), d) self.assertEqual(cf.ge(cf.dt(2002, 6, 16)), d) self.assertNotEqual(cf.ge(cf.dt('2100-1-1')), d) self.assertNotEqual( cf.ge(cf.dt('2001-1-1')) & cf.ge(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertEqual(cf.gt(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.gt(cf.dt(2002, 6, 16)), d) self.assertNotEqual(cf.gt(cf.dt('2100-1-1')), d) self.assertEqual( cf.gt(cf.dt('2001-1-1')) & cf.le(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertEqual(cf.ne(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.ne(cf.dt(2002, 6, 16)), d) self.assertEqual(cf.ne(cf.dt('2100-1-1')), d) self.assertEqual( cf.ne(cf.dt('2001-1-1')) & cf.ne(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertNotEqual(cf.le(cf.dt(1990, 1, 1)), d) self.assertEqual(cf.le(cf.dt(2002, 6, 16)), d) self.assertEqual(cf.le(cf.dt('2100-1-1')), d) self.assertNotEqual( cf.le(cf.dt('2001-1-1')) & cf.le(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertNotEqual(cf.lt(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.lt(cf.dt(2002, 6, 16)), d) self.assertEqual(cf.lt(cf.dt('2100-1-1')), d) self.assertNotEqual( cf.lt(cf.dt('2001-1-1')) & cf.lt(cf.dt(2010, 12, 31)), d)
def test_Domain_subspace(self): f = self.d.copy() x = f.dimension_coordinate("X") a = x.varray a[...] = numpy.arange(0, 360, 40) x.set_bounds(x.create_bounds()) f.cyclic("X", iscyclic=True, period=360) f0 = f.copy() # wi (increasing) g = f.subspace(grid_longitude=cf.wi(50, 130)) self.assertEqual(g.size, 20) x = g.construct("grid_longitude").array self.assertTrue((x == [80, 120]).all()) g = f.subspace(grid_longitude=cf.wi(-90, 50)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-80, -40, 0, 40]).all()) g = f.subspace(grid_longitude=cf.wi(310, 450)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-40, 0, 40, 80]).all()) g = f.subspace(grid_longitude=cf.wi(310 - 1080, 450 - 1080)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-40, 0, 40, 80]).all()) g = f.subspace(grid_longitude=cf.wi(310 + 720, 450 + 720)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-40, 0, 40, 80]).all()) g = f.subspace(grid_longitude=cf.wi(-90, 370)) self.assertEqual(g.size, 90) x = g.construct("grid_longitude").array self.assertTrue((x == [-80, -40, 0, 40, 80, 120, 160, 200, 240.0]).all()) with self.assertRaises(IndexError): f.indices(grid_longitude=cf.wi(90, 100)) # wi (decreasing) f.flip("X", inplace=True) g = f.subspace(grid_longitude=cf.wi(50, 130)) self.assertEqual(g.size, 20) x = g.construct("grid_longitude").array self.assertTrue((x == [80, 120][::-1]).all()) g = f.subspace(grid_longitude=cf.wi(-90, 50)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-80, -40, 0, 40][::-1]).all()) g = f.subspace(grid_longitude=cf.wi(310, 450)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-40, 0, 40, 80][::-1]).all()) g = f.subspace(grid_longitude=cf.wi(310 - 1080, 450 - 1080)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-40, 0, 40, 80][::-1]).all()) g = f.subspace(grid_longitude=cf.wi(310 + 720, 450 + 720)) self.assertEqual(g.size, 40) x = g.construct("grid_longitude").array self.assertTrue((x == [-40, 0, 40, 80][::-1]).all()) with self.assertRaises(IndexError): f.indices(grid_longitude=cf.wi(90, 100)) # wo f = f0.copy() g = f.subspace(grid_longitude=cf.wo(50, 130)) self.assertEqual(g.size, 70) x = g.construct("grid_longitude").array self.assertTrue((x == [-200, -160, -120, -80, -40, 0, 40]).all()) with self.assertRaises(IndexError): f.indices(grid_longitude=cf.wo(-90, 370)) # set g = f.subspace(grid_longitude=cf.set([320, 40, 80, 99999])) self.assertEqual(g.size, 30) x = g.construct("grid_longitude").array self.assertTrue((x == [40, 80, 320]).all()) g = f.subspace(grid_longitude=cf.lt(90)) self.assertEqual(g.size, 30) x = g.construct("grid_longitude").array self.assertTrue((x == [0, 40, 80]).all()) g = f.subspace(grid_longitude=cf.gt(90)) self.assertEqual(g.size, 60) x = g.construct("grid_longitude").array self.assertTrue((x == [120, 160, 200, 240, 280, 320]).all()) g = f.subspace(grid_longitude=cf.le(80)) self.assertEqual(g.size, 30) x = g.construct("grid_longitude").array self.assertTrue((x == [0, 40, 80]).all()) g = f.subspace(grid_longitude=cf.ge(80)) self.assertEqual(g.size, 70) x = g.construct("grid_longitude").array self.assertTrue((x == [80, 120, 160, 200, 240, 280, 320]).all()) # 2-d lon = f.auxiliary_coordinate("X") lon.data[...] = numpy.arange(60, 150).reshape(9, 10) lat = f.auxiliary_coordinate("Y") lat.data[...] = numpy.arange(-45, 45).reshape(10, 9) for mode in ("compress", "envelope"): g = f.subspace(mode, longitude=cf.wi(92, 134)) size = 50 self.assertEqual(g.size, size) for mode in (("compress", ), ("envelope", )): g = f.subspace(*mode, longitude=cf.wi(72, 83) | cf.gt(118)) if mode == ("envelope", ): size = 80 else: size = 60 self.assertEqual(g.size, size, mode) for mode in ("compress", "envelope"): g = f.subspace(mode, grid_longitude=cf.contains(23.2)) size = 10 self.assertEqual(g.size, size) self.assertEqual(g.construct("grid_longitude").array, 40) for mode in ("compress", "envelope"): g = f.subspace(mode, grid_latitude=cf.contains(1)) size = 9 self.assertEqual(g.size, size) self.assertEqual(g.construct("grid_latitude").array, 0.88) for mode in ("compress", "envelope"): g = f.subspace(mode, longitude=cf.contains(83)) size = 1 self.assertEqual(g.size, size) self.assertEqual(g.construct("longitude").array, 83) # Calls that should fail with self.assertRaises(Exception): f.subspace(grid_longitude=cf.gt(23), X=cf.wi(92, 134)) with self.assertRaises(Exception): f.subspace(grid_longitude=cf.gt(23), longitude=cf.wi(92, 134)) with self.assertRaises(Exception): f.subspace(grid_latitude=cf.contains(-23.2))
def test_Query_evaluate(self): for x in (5, cf.Data(5, "kg m-2"), cf.Data([5], "kg m-2 s-1")): self.assertEqual(x, cf.eq(5)) self.assertEqual(x, cf.lt(8)) self.assertEqual(x, cf.le(8)) self.assertEqual(x, cf.gt(3)) self.assertEqual(x, cf.ge(3)) self.assertEqual(x, cf.wi(3, 8)) self.assertEqual(x, cf.wo(8, 11)) self.assertEqual(x, cf.set([3, 5, 8])) self.assertEqual(cf.eq(5), x) self.assertEqual(cf.lt(8), x) self.assertEqual(cf.le(8), x) self.assertEqual(cf.gt(3), x) self.assertEqual(cf.ge(3), x) self.assertEqual(cf.wi(3, 8), x) self.assertEqual(cf.wo(8, 11), x) self.assertEqual(cf.set([3, 5, 8]), x) self.assertNotEqual(x, cf.eq(8)) self.assertNotEqual(x, cf.lt(3)) self.assertNotEqual(x, cf.le(3)) self.assertNotEqual(x, cf.gt(8)) self.assertNotEqual(x, cf.ge(8)) self.assertNotEqual(x, cf.wi(8, 11)) self.assertNotEqual(x, cf.wo(3, 8)) self.assertNotEqual(x, cf.set([3, 8, 11])) # Test that the evaluation is commutative i.e. A == B # means B == A self.assertNotEqual(x, cf.eq(8)) self.assertNotEqual(x, cf.lt(3)) self.assertNotEqual(x, cf.le(3)) self.assertNotEqual(x, cf.gt(8)) self.assertNotEqual(x, cf.ge(8)) self.assertNotEqual(x, cf.wi(8, 11)) self.assertNotEqual(x, cf.wo(3, 8)) self.assertNotEqual(x, cf.set([3, 8, 11])) self.assertNotEqual(cf.eq(8), x) self.assertNotEqual(cf.lt(3), x) self.assertNotEqual(cf.le(3), x) self.assertNotEqual(cf.gt(8), x) self.assertNotEqual(cf.ge(8), x) self.assertNotEqual(cf.wi(8, 11), x) self.assertNotEqual(cf.wo(3, 8), x) self.assertNotEqual(cf.set([3, 8, 11]), x) # --- End: for c = cf.wi(2, 4) d = cf.wi(6, 8) e = d | c self.assertTrue(c.evaluate(3)) self.assertFalse(c.evaluate(5)) self.assertTrue(e.evaluate(3)) self.assertTrue(e.evaluate(7)) self.assertFalse(e.evaluate(5)) self.assertEqual(3, c) self.assertNotEqual(5, c) self.assertEqual(c, 3) self.assertNotEqual(c, 5) self.assertEqual(3, e) self.assertEqual(7, e) self.assertNotEqual(5, e) self.assertEqual(e, 3) self.assertEqual(e, 7) self.assertNotEqual(e, 5) x = "qwerty" self.assertEqual(x, cf.eq("qwerty")) self.assertEqual(x, cf.eq(re.compile("^qwerty$"))) self.assertEqual(x, cf.eq(re.compile("qwe"))) self.assertEqual(x, cf.eq(re.compile("qwe.*"))) self.assertEqual(x, cf.eq(re.compile(".*qwe"))) self.assertEqual(x, cf.eq(re.compile(".*rty"))) self.assertEqual(x, cf.eq(re.compile(".*rty$"))) self.assertEqual(x, cf.eq(re.compile("^.*rty$"))) self.assertEqual(x, cf.eq(re.compile("rty$"))) self.assertNotEqual(x, cf.eq("QWERTY")) self.assertNotEqual(x, cf.eq(re.compile("QWERTY"))) self.assertNotEqual(x, cf.eq(re.compile("^QWERTY$"))) self.assertNotEqual(x, cf.eq(re.compile("QWE"))) self.assertNotEqual(x, cf.eq(re.compile("QWE.*"))) self.assertNotEqual(x, cf.eq(re.compile(".*QWE"))) self.assertNotEqual(x, cf.eq(re.compile(".*RTY"))) self.assertNotEqual(x, cf.eq(re.compile(".*RTY$"))) self.assertNotEqual(x, cf.eq(re.compile("^.*RTY$")))
def test_Query_dteq_dtne_dtge_dtgt_dtle_dtlt(self): d = cf.Data([[1.0, 5.0], [6, 2]], "days since 2000-12-29 21:00:00") message = "Diff =" + str( (d - cf.Data(cf.dt("2001-01-03 21:00:00", calendar="standard"))).array) self.assertTrue( (d == cf.eq(cf.dt("2001-01-03 21:00:00"))).equals( cf.Data([[False, True], [False, False]])), message, ) self.assertTrue( (d == cf.ne(cf.dt("2001-01-03 21:00:00"))).equals( cf.Data([[True, False], [True, True]])), message, ) self.assertTrue( (d == cf.ge(cf.dt("2001-01-03 21:00:00"))).equals( cf.Data([[False, True], [True, False]])), message, ) self.assertTrue( (d == cf.gt(cf.dt("2001-01-03 21:00:00"))).equals( cf.Data([[False, False], [True, False]])), message, ) self.assertTrue( (d == cf.le(cf.dt("2001-01-03 21:00:00"))).equals( cf.Data([[True, True], [False, True]])), message, ) self.assertTrue( (d == cf.lt(cf.dt("2001-01-03 21:00:00"))).equals( cf.Data([[True, False], [False, True]])), message, ) self.assertTrue( (d == cf.eq(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[False, True], [False, False]])), message, ) self.assertTrue( (d == cf.ne(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[True, False], [True, True]])), message, ) self.assertTrue( (d == cf.ge(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[False, True], [True, False]])), message, ) self.assertTrue( (d == cf.gt(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[False, False], [True, False]])), message, ) self.assertTrue( (d == cf.le(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[True, True], [False, True]])), message, ) self.assertTrue( (d == cf.lt(cf.dt(2001, 1, 3, 21, 0, 0))).equals( cf.Data([[True, False], [False, True]])), message, ) d = cf.dt(2002, 6, 16) self.assertEqual(cf.eq(cf.dt(2002, 6, 16)), d) self.assertNotEqual(cf.eq(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.eq(cf.dt("2100-1-1")), d) self.assertNotEqual( cf.eq(cf.dt("2001-1-1")) & cf.eq(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertEqual(cf.ge(cf.dt(1990, 1, 1)), d) self.assertEqual(cf.ge(cf.dt(2002, 6, 16)), d) self.assertNotEqual(cf.ge(cf.dt("2100-1-1")), d) self.assertNotEqual( cf.ge(cf.dt("2001-1-1")) & cf.ge(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertEqual(cf.gt(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.gt(cf.dt(2002, 6, 16)), d) self.assertNotEqual(cf.gt(cf.dt("2100-1-1")), d) self.assertEqual( cf.gt(cf.dt("2001-1-1")) & cf.le(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertEqual(cf.ne(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.ne(cf.dt(2002, 6, 16)), d) self.assertEqual(cf.ne(cf.dt("2100-1-1")), d) self.assertEqual( cf.ne(cf.dt("2001-1-1")) & cf.ne(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertNotEqual(cf.le(cf.dt(1990, 1, 1)), d) self.assertEqual(cf.le(cf.dt(2002, 6, 16)), d) self.assertEqual(cf.le(cf.dt("2100-1-1")), d) self.assertNotEqual( cf.le(cf.dt("2001-1-1")) & cf.le(cf.dt(2010, 12, 31)), d) d = cf.dt(2002, 6, 16) self.assertNotEqual(cf.lt(cf.dt(1990, 1, 1)), d) self.assertNotEqual(cf.lt(cf.dt(2002, 6, 16)), d) self.assertEqual(cf.lt(cf.dt("2100-1-1")), d) self.assertNotEqual( cf.lt(cf.dt("2001-1-1")) & cf.lt(cf.dt(2010, 12, 31)), d)
def test_FieldList_select_by_construct(self): x = self.x.copy() x.del_construct("time") f = cf.FieldList(x) f.extend(self.f2.copy()) g = f.select_by_construct() self.assertEqual(len(g), 2) g = f.select_by_construct("latitude") self.assertEqual(len(g), 2) g = f.select_by_construct("latitude", "longitude") self.assertEqual(len(g), 2) g = f.select_by_construct("latitude", "time") self.assertEqual(len(g), 1) g = f.select_by_construct("latitude", "time", OR=False) self.assertEqual(len(g), 1) g = f.select_by_construct("latitude", "time", OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(0)) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01"))) self.assertEqual(len(g), 1) g = f.select_by_construct(longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01")), OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct( "longitude", longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01")), OR=True, ) self.assertEqual(len(g), 2) g = f.select_by_construct( "latitude", longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01")), OR=True, ) self.assertEqual(len(g), 2) g = f.select_by_construct( "time", longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01")), OR=True, ) self.assertEqual(len(g), 2) g = f.select_by_construct( "time", longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01")), OR=False, ) self.assertEqual(len(g), 1) g = f.select_by_construct( "time", longitude=cf.gt(0), time=cf.le(cf.dt("2008-12-01")), OR=False, ) self.assertEqual(len(g), 1) g = f.select_by_construct("qwerty") self.assertEqual(len(g), 0) g = f.select_by_construct("qwerty", "latitude") self.assertEqual(len(g), 0) g = f.select_by_construct("qwerty", "latitude", OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct("qwerty", "time", "longitude") self.assertEqual(len(g), 0) g = f.select_by_construct("qwerty", "time", "longitude", OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(7.6)) self.assertEqual(len(g), 1) g = f.select_by_construct(longitude=cf.gt(0), time=cf.le(cf.dt("1999-12-01"))) self.assertEqual(len(g), 0)
def test_FieldList_select_by_construct(self): if self.test_only and inspect.stack()[0][3] not in self.test_only: return x = self.x.copy() x.del_construct('time') f = cf.FieldList(x) f.extend(self.f2.copy()) g = f.select_by_construct() self.assertEqual(len(g), 2) g = f.select_by_construct('latitude') self.assertEqual(len(g), 2) g = f.select_by_construct('latitude', 'longitude') self.assertEqual(len(g), 2) g = f.select_by_construct('latitude', 'time') self.assertEqual(len(g), 1) g = f.select_by_construct('latitude', 'time', OR=False) self.assertEqual(len(g), 1) g = f.select_by_construct('latitude', 'time', OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(0)) self.assertEqual(len(g), 2) g = f.select_by_construct( longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01'))) self.assertEqual(len(g), 1) g = f.select_by_construct( longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct( 'longitude', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True ) self.assertEqual(len(g), 2) g = f.select_by_construct( 'latitude', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True ) self.assertEqual(len(g), 2) g = f.select_by_construct( 'time', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=True ) self.assertEqual(len(g), 2) g = f.select_by_construct( 'time', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=False ) self.assertEqual(len(g), 1) g = f.select_by_construct( 'time', longitude=cf.gt(0), time=cf.le(cf.dt('2008-12-01')), OR=False ) self.assertEqual(len(g), 1) g = f.select_by_construct('qwerty') self.assertEqual(len(g), 0) g = f.select_by_construct('qwerty', 'latitude') self.assertEqual(len(g), 0) g = f.select_by_construct('qwerty', 'latitude', OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct('qwerty', 'time', 'longitude') self.assertEqual(len(g), 0) g = f.select_by_construct('qwerty', 'time', 'longitude', OR=True) self.assertEqual(len(g), 2) g = f.select_by_construct(longitude=cf.gt(7.6)) self.assertEqual(len(g), 1) g = f.select_by_construct( longitude=cf.gt(0), time=cf.le(cf.dt('1999-12-01'))) self.assertEqual(len(g), 0)