本文整理汇总了Python中pandas.core.dtypes.dtypes.DatetimeTZDtype.construct_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python DatetimeTZDtype.construct_from_string方法的具体用法?Python DatetimeTZDtype.construct_from_string怎么用?Python DatetimeTZDtype.construct_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.dtypes.dtypes.DatetimeTZDtype
的用法示例。
在下文中一共展示了DatetimeTZDtype.construct_from_string方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_construct_from_string_raises
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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]'])
示例2: test_construction_from_string
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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')
示例3: test_construction_from_string
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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'))
示例4: validate_tz_from_dtype
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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
示例5: test_parser
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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
示例6: test_subclass
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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))
示例7: test_datetimetz_dtype
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
def test_datetimetz_dtype(self, dtype):
assert (com.pandas_dtype(dtype) ==
DatetimeTZDtype.construct_from_string(dtype))
assert com.pandas_dtype(dtype) == dtype
示例8: assert
# 需要导入模块: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
# 或者: from pandas.core.dtypes.dtypes.DatetimeTZDtype import construct_from_string [as 别名]
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)