Python numpy.lib.format.read_array() Examples

The following are code examples for showing how to use numpy.lib.format.read_array(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: LaserTOF   Author: kyleuckert   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 2
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 3
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_format.py    MIT License 6 votes vote down vote up
def test_unicode_field_names():
    # gh-7391
    arr = np.array([
        (1, 3),
        (1, 2),
        (1, 3),
        (1, 2)
    ], dtype=[
        ('int', int),
        (u'\N{CJK UNIFIED IDEOGRAPH-6574}\N{CJK UNIFIED IDEOGRAPH-5F62}', int)
    ])
    fname = os.path.join(tempdir, "unicode.npy")
    with open(fname, 'wb') as f:
        format.write_array(f, arr, version=(3, 0))
    with open(fname, 'rb') as f:
        arr2 = format.read_array(f)
    assert_array_equal(arr, arr2)

    # notifies the user that 3.0 is selected
    with open(fname, 'wb') as f:
        with assert_warns(UserWarning):
            format.write_array(f, arr, version=None) 
Example 4
Project: recruit   Author: Frank-qlu   File: test_format.py    Apache License 2.0 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 5
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 6
Project: MARRtino-2.0   Author: DaniAffCH   File: test_format.py    GNU General Public License v3.0 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 7
Project: MARRtino-2.0   Author: DaniAffCH   File: test_format.py    GNU General Public License v3.0 6 votes vote down vote up
def test_unicode_field_names():
    # gh-7391
    arr = np.array([
        (1, 3),
        (1, 2),
        (1, 3),
        (1, 2)
    ], dtype=[
        ('int', int),
        (u'\N{CJK UNIFIED IDEOGRAPH-6574}\N{CJK UNIFIED IDEOGRAPH-5F62}', int)
    ])
    fname = os.path.join(tempdir, "unicode.npy")
    with open(fname, 'wb') as f:
        format.write_array(f, arr, version=(3, 0))
    with open(fname, 'rb') as f:
        arr2 = format.read_array(f)
    assert_array_equal(arr, arr2)

    # notifies the user that 3.0 is selected
    with open(fname, 'wb') as f:
        with assert_warns(UserWarning):
            format.write_array(f, arr, version=None) 
Example 8
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 9
Project: vnpy_crypto   Author: birforce   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 10
Project: ble5-nrf52-mac   Author: tomasero   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 11
Project: poker   Author: surgebiswas   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 12
Project: P3_image_processing   Author: latedude2   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 13
Project: P3_image_processing   Author: latedude2   File: test_format.py    MIT License 6 votes vote down vote up
def test_unicode_field_names():
    # gh-7391
    arr = np.array([
        (1, 3),
        (1, 2),
        (1, 3),
        (1, 2)
    ], dtype=[
        ('int', int),
        (u'\N{CJK UNIFIED IDEOGRAPH-6574}\N{CJK UNIFIED IDEOGRAPH-5F62}', int)
    ])
    fname = os.path.join(tempdir, "unicode.npy")
    with open(fname, 'wb') as f:
        format.write_array(f, arr, version=(3, 0))
    with open(fname, 'rb') as f:
        arr2 = format.read_array(f)
    assert_array_equal(arr, arr2)

    # notifies the user that 3.0 is selected
    with open(fname, 'wb') as f:
        with assert_warns(UserWarning):
            format.write_array(f, arr, version=None) 
Example 14
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_format.py    MIT License 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 15
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 16
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 17
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_format.py    Apache License 2.0 6 votes vote down vote up
def test_version_2_0():
    f = BytesIO()
    # requires more than 2 byte for header
    dt = [(("%d" % i) * 100, float) for i in range(500)]
    d = np.ones(1000, dtype=dt)

    format.write_array(f, d, version=(2, 0))
    with warnings.catch_warnings(record=True) as w:
        warnings.filterwarnings('always', '', UserWarning)
        format.write_array(f, d)
        assert_(w[0].category is UserWarning)

    # check alignment of data portion
    f.seek(0)
    header = f.readline()
    assert_(len(header) % format.ARRAY_ALIGN == 0)

    f.seek(0)
    n = format.read_array(f)
    assert_array_equal(d, n)

    # 1.0 requested but data cannot be saved this way
    assert_raises(ValueError, format.write_array, f, d, (1, 0)) 
Example 18
Project: LaserTOF   Author: kyleuckert   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 19
Project: LaserTOF   Author: kyleuckert   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 20
Project: LaserTOF   Author: kyleuckert   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 21
Project: LaserTOF   Author: kyleuckert   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 22
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2, allow_pickle=True)
    return arr2 
Example 23
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 24
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 25
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 26
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: pickle.py    MIT License 5 votes vote down vote up
def _unpickle_array(bytes):
    arr = read_array(BytesIO(bytes))

    return arr 
Example 27
Project: recruit   Author: Frank-qlu   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 28
Project: recruit   Author: Frank-qlu   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 29
Project: recruit   Author: Frank-qlu   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 30
Project: recruit   Author: Frank-qlu   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 31
Project: recruit   Author: Frank-qlu   File: pickle.py    Apache License 2.0 5 votes vote down vote up
def _unpickle_array(bytes):
    arr = read_array(BytesIO(bytes))

    return arr 
Example 32
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 33
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 34
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 35
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 36
Project: FUTU_Stop_Loss   Author: BigtoC   File: pickle.py    MIT License 5 votes vote down vote up
def _unpickle_array(bytes):
    arr = read_array(BytesIO(bytes))

    # All datetimes should be stored as M8[ns].  When unpickling with
    # numpy1.6, it will read these as M8[us].  So this ensures all
    # datetime64 types are read as MS[ns]
    if is_datetime64_dtype(arr):
        arr = arr.view(_NS_DTYPE)

    return arr 
Example 37
Project: MARRtino-2.0   Author: DaniAffCH   File: test_format.py    GNU General Public License v3.0 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2, allow_pickle=True)
    return arr2 
Example 38
Project: MARRtino-2.0   Author: DaniAffCH   File: test_format.py    GNU General Public License v3.0 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 39
Project: MARRtino-2.0   Author: DaniAffCH   File: test_format.py    GNU General Public License v3.0 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 40
Project: MARRtino-2.0   Author: DaniAffCH   File: test_format.py    GNU General Public License v3.0 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 41
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 42
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 43
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 44
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 45
Project: vnpy_crypto   Author: birforce   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 46
Project: vnpy_crypto   Author: birforce   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 47
Project: vnpy_crypto   Author: birforce   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 48
Project: vnpy_crypto   Author: birforce   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 49
Project: ble5-nrf52-mac   Author: tomasero   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 50
Project: ble5-nrf52-mac   Author: tomasero   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 51
Project: ble5-nrf52-mac   Author: tomasero   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 52
Project: ble5-nrf52-mac   Author: tomasero   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 53
Project: Computable   Author: ktraunmueller   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 54
Project: Computable   Author: ktraunmueller   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 55
Project: Computable   Author: ktraunmueller   File: common.py    MIT License 5 votes vote down vote up
def _unpickle_array(bytes):
    arr = read_array(BytesIO(bytes))

    # All datetimes should be stored as M8[ns].  When unpickling with
    # numpy1.6, it will read these as M8[us].  So this ensures all
    # datetime64 types are read as MS[ns]
    if is_datetime64_dtype(arr):
        arr = arr.view(_NS_DTYPE)

    return arr 
Example 56
Project: poker   Author: surgebiswas   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 57
Project: poker   Author: surgebiswas   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 58
Project: poker   Author: surgebiswas   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 59
Project: poker   Author: surgebiswas   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 60
Project: P3_image_processing   Author: latedude2   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2, allow_pickle=True)
    return arr2 
Example 61
Project: P3_image_processing   Author: latedude2   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 62
Project: P3_image_processing   Author: latedude2   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 63
Project: P3_image_processing   Author: latedude2   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 64
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 65
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 66
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_format.py    MIT License 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 67
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_format.py    MIT License 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 68
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 69
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 70
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 71
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 72
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 73
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 74
Project: 3dprinteros-client   Author: panasevychol   File: test_format.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def test_read_version_1_0_bad_magic():
    for magic in bad_version_magic + malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_array), f 
Example 75
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2, allow_pickle=True)
    return arr2 
Example 76
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip_randsize(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIOSRandomSize(f.getvalue())
    arr2 = format.read_array(f2)
    return arr2 
Example 77
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip_truncated(arr):
    f = BytesIO()
    format.write_array(f, arr)
    #BytesIO is one byte short
    f2 = BytesIO(f.getvalue()[0:-1])
    arr2 = format.read_array(f2)
    return arr2 
Example 78
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        assert_raises(ValueError, format.read_array, f) 
Example 79
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: pickle.py    Apache License 2.0 5 votes vote down vote up
def _unpickle_array(bytes):
    arr = read_array(BytesIO(bytes))

    return arr 
Example 80
Project: fund   Author: Frank-qlu   File: test_format.py    Apache License 2.0 5 votes vote down vote up
def roundtrip(arr):
    f = BytesIO()
    format.write_array(f, arr)
    f2 = BytesIO(f.getvalue())
    arr2 = format.read_array(f2, allow_pickle=True)
    return arr2