當前位置: 首頁>>代碼示例>>Python>>正文


Python dtypes.DatetimeTZDtype類代碼示例

本文整理匯總了Python中pandas.core.dtypes.dtypes.DatetimeTZDtype的典型用法代碼示例。如果您正苦於以下問題:Python DatetimeTZDtype類的具體用法?Python DatetimeTZDtype怎麽用?Python DatetimeTZDtype使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DatetimeTZDtype類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_construct_from_string_raises

    def test_construct_from_string_raises(self):
        with pytest.raises(TypeError, match="notatz"):
            DatetimeTZDtype.construct_from_string('datetime64[ns, notatz]')

        with pytest.raises(TypeError,
                           match="^Could not construct DatetimeTZDtype$"):
            DatetimeTZDtype.construct_from_string(['datetime64[ns, notatz]'])
開發者ID:johnnychiuchiu,項目名稱:pandas,代碼行數:7,代碼來源:test_dtypes.py

示例2: test_construction_from_string

 def test_construction_from_string(self):
     result = DatetimeTZDtype.construct_from_string(
         'datetime64[ns, US/Eastern]')
     assert is_dtype_equal(self.dtype, result)
     msg = "Could not construct DatetimeTZDtype from 'foo'"
     with pytest.raises(TypeError, match=msg):
         DatetimeTZDtype.construct_from_string('foo')
開發者ID:chrish42,項目名稱:pandas,代碼行數:7,代碼來源:test_dtypes.py

示例3: test_construction_from_string

 def test_construction_from_string(self):
     result = DatetimeTZDtype('datetime64[ns, US/Eastern]')
     assert is_dtype_equal(self.dtype, result)
     result = DatetimeTZDtype.construct_from_string(
         'datetime64[ns, US/Eastern]')
     assert is_dtype_equal(self.dtype, result)
     pytest.raises(TypeError,
                   lambda: DatetimeTZDtype.construct_from_string('foo'))
開發者ID:mficek,項目名稱:pandas,代碼行數:8,代碼來源:test_dtypes.py

示例4: validate_tz_from_dtype

def validate_tz_from_dtype(dtype, tz):
    """
    If the given dtype is a DatetimeTZDtype, extract the implied
    tzinfo object from it and check that it does not conflict with the given
    tz.

    Parameters
    ----------
    dtype : dtype, str
    tz : None, tzinfo

    Returns
    -------
    tz : consensus tzinfo

    Raises
    ------
    ValueError : on tzinfo mismatch
    """
    if dtype is not None:
        try:
            dtype = DatetimeTZDtype.construct_from_string(dtype)
            dtz = getattr(dtype, 'tz', None)
            if dtz is not None:
                if tz is not None and not timezones.tz_compare(tz, dtz):
                    raise ValueError("cannot supply both a tz and a dtype"
                                     " with a tz")
                tz = dtz
        except TypeError:
            pass
    return tz
開發者ID:glyg,項目名稱:pandas,代碼行數:31,代碼來源:datetimelike.py

示例5: test_is_dtype

 def test_is_dtype(self):
     assert not DatetimeTZDtype.is_dtype(None)
     assert DatetimeTZDtype.is_dtype(self.dtype)
     assert DatetimeTZDtype.is_dtype('datetime64[ns, US/Eastern]')
     assert not DatetimeTZDtype.is_dtype('foo')
     assert DatetimeTZDtype.is_dtype(DatetimeTZDtype('ns', 'US/Pacific'))
     assert not DatetimeTZDtype.is_dtype(np.float64)
開發者ID:mficek,項目名稱:pandas,代碼行數:7,代碼來源:test_dtypes.py

示例6: test_is_dtype

 def test_is_dtype(self):
     self.assertFalse(DatetimeTZDtype.is_dtype(None))
     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))
開發者ID:tsdlovell,項目名稱:pandas,代碼行數:8,代碼來源:test_dtypes.py

示例7: test_parser

 def test_parser(self, tz, constructor):
     # pr #11245
     dtz_str = '{con}[ns, {tz}]'.format(con=constructor, tz=tz)
     result = DatetimeTZDtype.construct_from_string(dtz_str)
     expected = DatetimeTZDtype('ns', tz)
     assert result == expected
開發者ID:changhiskhan,項目名稱:pandas,代碼行數:6,代碼來源:test_dtypes.py

示例8: test_subclass

    def test_subclass(self):
        a = DatetimeTZDtype.construct_from_string('datetime64[ns, US/Eastern]')
        b = DatetimeTZDtype.construct_from_string('datetime64[ns, CET]')

        assert issubclass(type(a), type(a))
        assert issubclass(type(a), type(b))
開發者ID:changhiskhan,項目名稱:pandas,代碼行數:6,代碼來源:test_dtypes.py

示例9: test_datetimetz_dtype

 def test_datetimetz_dtype(self, dtype):
     assert (com.pandas_dtype(dtype) ==
             DatetimeTZDtype.construct_from_string(dtype))
     assert com.pandas_dtype(dtype) == dtype
開發者ID:clham,項目名稱:pandas,代碼行數:4,代碼來源:test_common.py

示例10: assert

    assert (not array_equivalent(m, n, strict_nan=False))


def test_array_equivalent_str():
    for dtype in ['O', 'S', 'U']:
        assert array_equivalent(np.array(['A', 'B'], dtype=dtype),
                                np.array(['A', 'B'], dtype=dtype))
        assert not array_equivalent(np.array(['A', 'B'], dtype=dtype),
                                    np.array(['A', 'X'], dtype=dtype))


@pytest.mark.parametrize('dtype, na_value', [
    # Datetime-like
    (np.dtype("M8[ns]"), NaT),
    (np.dtype("m8[ns]"), NaT),
    (DatetimeTZDtype.construct_from_string('datetime64[ns, US/Eastern]'), NaT),
    (PeriodDtype("M"), NaT),
    # Integer
    ('u1', 0), ('u2', 0), ('u4', 0), ('u8', 0),
    ('i1', 0), ('i2', 0), ('i4', 0), ('i8', 0),
    # Bool
    ('bool', False),
    # Float
    ('f2', np.nan), ('f4', np.nan), ('f8', np.nan),
    # Object
    ('O', np.nan),
    # Interval
    (IntervalDtype(), np.nan),
])
def test_na_value_for_dtype(dtype, na_value):
    result = na_value_for_dtype(dtype)
開發者ID:brianholland,項目名稱:pandas,代碼行數:31,代碼來源:test_missing.py


注:本文中的pandas.core.dtypes.dtypes.DatetimeTZDtype類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。