Example #1
0
 def test_single(self):
     for calendar in self.calendars:
         dt = cftime.datetime(**self.kwargs, calendar=calendar)
         actual = discard_microsecond(dt)
         expected = cftime.datetime(**self.kwargs,
                                    microsecond=0,
                                    calendar=calendar)
         self.assertEqual(expected, actual)
Example #2
0
    def test_multi(self):
        shape = (5, 2)
        n = np.prod(shape)

        dates = np.array([
            datetime.datetime(**self.kwargs, microsecond=i) for i in range(n)
        ]).reshape(shape)
        actual = discard_microsecond(dates)
        expected = np.array([self.expected] * n).reshape(shape)
        np.testing.assert_array_equal(expected, actual)
Example #3
0
    def test_multi(self):
        shape = (2, 5)
        n = np.prod(shape)

        for calendar in self.calendars:
            dates = np.array([
                cftime.datetime(**self.kwargs, calendar=calendar)
                for i in range(n)
            ]).reshape(shape)
            actual = discard_microsecond(dates)
            expected = np.array([
                cftime.datetime(
                    **self.kwargs, microsecond=0, calendar=calendar)
            ] * n).reshape(shape)
            np.testing.assert_array_equal(expected, actual)
Example #4
0
 def test_masked(self):
     data = [self.cftime, self.datetime, self.cftime, self.datetime]
     mask = [1, 0, 0, 1]
     dates = ma.masked_array(data, mask=mask)
     actual = discard_microsecond(dates)
     expected = np.array([
         ma.masked,
         datetime.datetime(**self.kwargs),
         cftime.datetime(**self.kwargs, calendar=self.calendar),
         ma.masked,
     ])
     self.assertEqual(expected.shape, actual.shape)
     for i, masked in enumerate(mask):
         if masked:
             self.assertIs(expected[i], actual[i])
         else:
             self.assertEqual(expected[i], actual[i])
Example #5
0
 def test_multi__falsy(self):
     falsy = np.array([None, False, 0])
     actual = discard_microsecond(falsy)
     np.testing.assert_array_equal(falsy, actual)
Example #6
0
 def test_single__false(self):
     self.assertFalse(discard_microsecond(False))
Example #7
0
 def test_single__none(self):
     self.assertIsNone(discard_microsecond(None))
Example #8
0
 def test_single(self):
     dt = datetime.datetime(**self.kwargs, microsecond=7)
     actual = discard_microsecond(dt)
     self.assertEqual(self.expected, actual)