def test_is_dtype(self): self.assertTrue(DatetimeTZDtype.is_dtype(self.dtype)) self.assertTrue(DatetimeTZDtype.is_dtype('datetime64[ns, US/Eastern]')) self.assertFalse(DatetimeTZDtype.is_dtype('foo')) self.assertTrue(DatetimeTZDtype.is_dtype(DatetimeTZDtype( 'ns', 'US/Pacific'))) self.assertFalse(DatetimeTZDtype.is_dtype(np.float64))
def test_parser(self): # pr #11245 for tz, constructor in product(('UTC', 'US/Eastern'), ('M8', 'datetime64')): self.assertEqual( DatetimeTZDtype('%s[ns, %s]' % (constructor, tz)), DatetimeTZDtype('ns', tz), )
def test_construction_from_string(self): result = DatetimeTZDtype('datetime64[ns, US/Eastern]') self.assertTrue(is_dtype_equal(self.dtype, result)) result = DatetimeTZDtype.construct_from_string( 'datetime64[ns, US/Eastern]') self.assertTrue(is_dtype_equal(self.dtype, result)) self.assertRaises(TypeError, lambda: DatetimeTZDtype.construct_from_string('foo'))
def test_construction_from_string(self): result = DatetimeTZDtype('datetime64[ns, US/Eastern]') self.assertTrue(is_dtype_equal(self.dtype, result)) result = DatetimeTZDtype.construct_from_string( 'datetime64[ns, US/Eastern]') self.assertTrue(is_dtype_equal(self.dtype, result)) self.assertRaises(TypeError, lambda: DatetimeTZDtype.construct_from_string('foo'))
def test_equality(self): self.assertTrue(is_dtype_equal(self.dtype, 'datetime64[ns, US/Eastern]')) self.assertTrue(is_dtype_equal(self.dtype, DatetimeTZDtype('ns','US/Eastern'))) self.assertFalse(is_dtype_equal(self.dtype, 'foo')) self.assertFalse(is_dtype_equal(self.dtype, DatetimeTZDtype('ns','CET'))) self.assertFalse(is_dtype_equal(DatetimeTZDtype('ns','US/Eastern'), DatetimeTZDtype('ns','US/Pacific'))) # numpy compat self.assertTrue(is_dtype_equal(np.dtype("M8[ns]"),"datetime64[ns]"))
def test_hash_vs_equality(self): # make sure that we satisfy is semantics dtype = self.dtype dtype2 = DatetimeTZDtype('ns', 'US/Eastern') dtype3 = DatetimeTZDtype(dtype2) self.assertTrue(dtype == dtype2) self.assertTrue(dtype2 == dtype) self.assertTrue(dtype3 == dtype) self.assertTrue(dtype is dtype2) self.assertTrue(dtype2 is dtype) self.assertTrue(dtype3 is dtype) self.assertTrue(hash(dtype) == hash(dtype2)) self.assertTrue(hash(dtype) == hash(dtype3))
def test_is_dtype(self): self.assertTrue(DatetimeTZDtype.is_dtype(self.dtype)) self.assertTrue(DatetimeTZDtype.is_dtype('datetime64[ns, US/Eastern]')) self.assertFalse(DatetimeTZDtype.is_dtype('foo')) self.assertTrue( DatetimeTZDtype.is_dtype(DatetimeTZDtype('ns', 'US/Pacific'))) self.assertFalse(DatetimeTZDtype.is_dtype(np.float64))
def test_is_dtype(self): self.assertTrue(DatetimeTZDtype.is_dtype(self.dtype)) self.assertTrue(DatetimeTZDtype.is_dtype("datetime64[ns, US/Eastern]")) self.assertFalse(DatetimeTZDtype.is_dtype("foo")) self.assertTrue(DatetimeTZDtype.is_dtype(DatetimeTZDtype("ns", "US/Pacific"))) self.assertFalse(DatetimeTZDtype.is_dtype(np.float64))
def test_subclass(self): a = DatetimeTZDtype('datetime64[ns, US/Eastern]') b = DatetimeTZDtype('datetime64[ns, CET]') self.assertTrue(issubclass(type(a), type(a))) self.assertTrue(issubclass(type(a), type(b)))
def test_construction(self): self.assertRaises(ValueError, lambda : DatetimeTZDtype('ms','US/Eastern'))
def setUp(self): self.dtype = DatetimeTZDtype('ns','US/Eastern')
def test_coerce_to_dtype(self): self.assertEqual(com._coerce_to_dtype('datetime64[ns, US/Eastern]'), DatetimeTZDtype('ns', 'US/Eastern')) self.assertEqual(com._coerce_to_dtype('datetime64[ns, Asia/Tokyo]'), DatetimeTZDtype('ns', 'Asia/Tokyo'))