本文整理汇总了Python中numpy.lib._iotools.StringConverter类的典型用法代码示例。如果您正苦于以下问题:Python StringConverter类的具体用法?Python StringConverter怎么用?Python StringConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringConverter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_upgrademapper
def test_upgrademapper(self):
"Tests updatemapper"
import dateutil.parser
import datetime
dateparser = dateutil.parser.parse
StringConverter.upgrade_mapper(dateparser, datetime.date(2000,1,1))
convert = StringConverter(dateparser, datetime.date(2000, 1, 1))
test = convert('2001-01-01')
assert_equal(test, datetime.datetime(2001, 01, 01, 00, 00, 00))
开发者ID:zoccolan,项目名称:eyetracker,代码行数:9,代码来源:test__iotools.py
示例2: test_upgrademapper
def test_upgrademapper(self):
"Tests updatemapper"
dateparser = _bytes_to_date
StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
convert = StringConverter(dateparser, date(2000, 1, 1))
test = convert(asbytes('2001-01-01'))
assert_equal(test, date(2001, 1, 1))
test = convert(asbytes('2009-01-01'))
assert_equal(test, date(2009, 1, 1))
test = convert(asbytes(''))
assert_equal(test, date(2000, 1, 1))
开发者ID:Garrett-R,项目名称:numpy,代码行数:11,代码来源:test__iotools.py
示例3: test_missing
def test_missing(self):
"Tests the use of missing values."
converter = StringConverter(missing_values=("missing", "missed"))
converter.upgrade("0")
assert_equal(converter("0"), 0)
assert_equal(converter(""), converter.default)
assert_equal(converter("missing"), converter.default)
assert_equal(converter("missed"), converter.default)
try:
converter("miss")
except ValueError:
pass
开发者ID:kidaa,项目名称:Neuroimaging,代码行数:12,代码来源:test__iotools.py
示例4: test_missing
def test_missing(self):
"Tests the use of missing values."
converter = StringConverter(missing_values=('missing','missed'))
converter.upgrade('0')
assert_equal(converter('0'), 0)
assert_equal(converter(''), converter.default)
assert_equal(converter('missing'), converter.default)
assert_equal(converter('missed'), converter.default)
try:
converter('miss')
except ValueError:
pass
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:12,代码来源:test__iotools.py
示例5: test_upgrademapper
def test_upgrademapper(self):
"Tests updatemapper"
from datetime import date
import time
dateparser = lambda s : date(*time.strptime(s, "%Y-%m-%d")[:3])
StringConverter.upgrade_mapper(dateparser, date(2000,1,1))
convert = StringConverter(dateparser, date(2000, 1, 1))
test = convert('2001-01-01')
assert_equal(test, date(2001, 01, 01))
test = convert('2009-01-01')
assert_equal(test, date(2009, 01, 01))
test = convert('')
assert_equal(test, date(2000, 01, 01))
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:13,代码来源:test__iotools.py
示例6: test_upgrademapper
def test_upgrademapper(self):
"Tests updatemapper"
if hasattr(sys, 'gettotalrefcount'):
# skip this test when Python was compiled using --with-pydebug
return
dateparser = _bytes_to_date
StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
convert = StringConverter(dateparser, date(2000, 1, 1))
test = convert(asbytes('2001-01-01'))
assert_equal(test, date(2001, 01, 01))
test = convert(asbytes('2009-01-01'))
assert_equal(test, date(2009, 01, 01))
test = convert(asbytes(''))
assert_equal(test, date(2000, 01, 01))
开发者ID:258073127,项目名称:MissionPlanner,代码行数:15,代码来源:test__iotools.py
示例7: test_upgrade
def test_upgrade(self):
"Tests the upgrade method."
converter = StringConverter()
assert_equal(converter._status, 0)
converter.upgrade(asbytes('0'))
assert_equal(converter._status, 1)
converter.upgrade(asbytes('0.'))
assert_equal(converter._status, 2)
converter.upgrade(asbytes('0j'))
assert_equal(converter._status, 3)
converter.upgrade(asbytes('a'))
assert_equal(converter._status, len(converter._mapper) - 1)
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:12,代码来源:test__iotools.py
示例8: test_upgrade
def test_upgrade(self):
"Tests the upgrade method."
converter = StringConverter()
assert_equal(converter._status, 0)
converter.upgrade("0")
assert_equal(converter._status, 1)
converter.upgrade("0.")
assert_equal(converter._status, 2)
converter.upgrade("0j")
assert_equal(converter._status, 3)
converter.upgrade("a")
assert_equal(converter._status, len(converter._mapper) - 1)
开发者ID:kidaa,项目名称:Neuroimaging,代码行数:12,代码来源:test__iotools.py
示例9: test_upgrade
def test_upgrade(self):
"Tests the upgrade method."
converter = StringConverter()
assert_equal(converter._status, 0)
# test int
assert_equal(converter.upgrade(asbytes('0')), 0)
assert_equal(converter._status, 1)
# test float
assert_allclose(converter.upgrade(asbytes('0.')), 0.0)
assert_equal(converter._status, 2)
# test complex
assert_equal(converter.upgrade(asbytes('0j')), complex('0j'))
assert_equal(converter._status, 3)
# test str
assert_equal(converter.upgrade(asbytes('a')), asbytes('a'))
assert_equal(converter._status, len(converter._mapper) - 1)
开发者ID:Garrett-R,项目名称:numpy,代码行数:16,代码来源:test__iotools.py
示例10: test_upgrade
def test_upgrade(self):
"Tests the upgrade method."
converter = StringConverter()
assert_equal(converter._status, 0)
# test int
assert_equal(converter.upgrade(b'0'), 0)
assert_equal(converter._status, 1)
# On systems where integer defaults to 32-bit, the statuses will be
# offset by one, so we check for this here.
import numpy.core.numeric as nx
status_offset = int(nx.dtype(nx.integer).itemsize < nx.dtype(nx.int64).itemsize)
# test int > 2**32
assert_equal(converter.upgrade(b'17179869184'), 17179869184)
assert_equal(converter._status, 1 + status_offset)
# test float
assert_allclose(converter.upgrade(b'0.'), 0.0)
assert_equal(converter._status, 2 + status_offset)
# test complex
assert_equal(converter.upgrade(b'0j'), complex('0j'))
assert_equal(converter._status, 3 + status_offset)
# test str
assert_equal(converter.upgrade(b'a'), b'a')
assert_equal(converter._status, len(converter._mapper) - 1)
开发者ID:BranYang,项目名称:numpy,代码行数:30,代码来源:test__iotools.py
示例11: test_keep_default
def test_keep_default(self):
"Make sure we don't lose an explicit default"
converter = StringConverter(None, missing_values="", default=-999)
converter.upgrade("3.14159265")
assert_equal(converter.default, -999)
assert_equal(converter.type, np.dtype(float))
#
converter = StringConverter(None, missing_values="", default=0)
converter.upgrade("3.14159265")
assert_equal(converter.default, 0)
assert_equal(converter.type, np.dtype(float))
开发者ID:kidaa,项目名称:Neuroimaging,代码行数:11,代码来源:test__iotools.py
示例12: test_upgrade
def test_upgrade(self):
"Tests the upgrade method."
converter = StringConverter()
assert_equal(converter._status, 0)
# test int
assert_equal(converter.upgrade('0'), 0)
assert_equal(converter._status, 1)
# On systems where long defaults to 32-bit, the statuses will be
# offset by one, so we check for this here.
import numpy.core.numeric as nx
status_offset = int(nx.dtype(nx.int_).itemsize < nx.dtype(nx.int64).itemsize)
# test int > 2**32
assert_equal(converter.upgrade('17179869184'), 17179869184)
assert_equal(converter._status, 1 + status_offset)
# test float
assert_allclose(converter.upgrade('0.'), 0.0)
assert_equal(converter._status, 2 + status_offset)
# test complex
assert_equal(converter.upgrade('0j'), complex('0j'))
assert_equal(converter._status, 3 + status_offset)
# test str
# note that the longdouble type has been skipped, so the
# _status increases by 2. Everything should succeed with
# unicode conversion (5).
for s in ['a', u'a', b'a']:
res = converter.upgrade(s)
assert_(type(res) is unicode)
assert_equal(res, u'a')
assert_equal(converter._status, 5 + status_offset)
开发者ID:Horta,项目名称:numpy,代码行数:36,代码来源:test__iotools.py
注:本文中的numpy.lib._iotools.StringConverter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论