Beispiel #1
0
 def test_02_automatic_mode(self):
     with self.assertRaises(RuntimeError):
         self.indexer.dayofyear
     pub.timegrids = timetools.Timegrids(
         timetools.Timegrid('01.01.2004', '1.01.2005', '1d'))
     self.assertIsInstance(self.indexer.dayofyear, numpy.ndarray)
     self.assertEqual(len(self.indexer.dayofyear), 366)
     self.assertTupleEqual(tuple(self.indexer.dayofyear), tuple(range(366)))
     pub.timegrids = timetools.Timegrids(
         timetools.Timegrid('01.01.2005', '1.01.2006', '1d'))
     del self.indexer.dayofyear
     self.assertIsInstance(self.indexer.dayofyear, numpy.ndarray)
     self.assertEqual(len(self.indexer.dayofyear), 365)
     self.assertTupleEqual(
         tuple(self.indexer.dayofyear),
         tuple(list(range(31 + 28)) + list(range(31 + 28 + 1, 366))))
     self.assertIs(self.indexer.dayofyear, self.indexer.dayofyear)
Beispiel #2
0
 def call_fset(
     self,
     obj: Any,
     value: Union[
         timetools.Timegrids,
         Tuple[
             timetools.DateConstrArg,
             timetools.DateConstrArg,
             timetools.PeriodConstrArg,
         ],
     ],
 ) -> None:
     """Try to convert the given input value(s)."""
     try:
         timegrids = timetools.Timegrids(*value)
     except TypeError:
         timegrids = timetools.Timegrids(value)  # type: ignore
         # this will most likely fail, we just want to reuse
         # the standard error message
     super().call_fset(obj, timegrids)
Beispiel #3
0
 def test_02_automatic_mode(self):
     with self.assertRaises(RuntimeError):
         self.indexer.monthofyear
     pub.timegrids = timetools.Timegrids(
         timetools.Timegrid('01.01.2004', '1.01.2005', '1d'))
     self.assertIsInstance(self.indexer.monthofyear, numpy.ndarray)
     self.assertEqual(len(self.indexer.monthofyear), 366)
     self.assertTupleEqual(
         tuple(self.indexer.monthofyear),
         tuple(31 * [0] + 29 * [1] + 31 * [2] + 30 * [3] + 31 * [4] +
               30 * [5] + 31 * [6] + 31 * [7] + 30 * [8] + 31 * [9] +
               30 * [10] + 31 * [11]))
     self.assertIs(self.indexer.monthofyear, self.indexer.monthofyear)
Beispiel #4
0
 def test_01_manual_mode(self):
     with self.assertRaises(BaseException):
         self.indexer.dayofyear = 'a'
     with self.assertRaises(BaseException):
         self.indexer.dayofyear = ['a', 'b']
     with self.assertRaises(ValueError):
         self.indexer.dayofyear = [[1, 2], [3, 4]]
     self.indexer.dayofyear = [1, 2]
     self.assertIsInstance(self.indexer.dayofyear, numpy.ndarray)
     self.assertTupleEqual(tuple(self.indexer.dayofyear), (1, 2))
     del self.indexer.dayofyear
     self.assertIsNone(self.indexer._dayofyear)
     pub.timegrids = timetools.Timegrids(
         timetools.Timegrid('01.01.2004', '1.01.2005', '1d'))
     with self.assertRaises(ValueError):
         self.indexer.dayofyear = [1, 2]
Beispiel #5
0
 def timegrids(self, args):
     # pylint: disable=missing-docstring, no-self-use
     try:
         return timetools.Timegrids(*args)
     except TypeError:
         return timetools.Timegrids(args)