Esempio n. 1
0
    def compare(self, vf, version):
        # GH12277 encoding default used to be latin-1, now utf-8
        if LooseVersion(version) < '0.18.0':
            data = read_msgpack(vf, encoding='latin-1')
        else:
            data = read_msgpack(vf)
        self.check_min_structure(data)
        for typ, dv in data.items():
            assert typ in self.all_data, ('unpacked data contains '
                                          'extra key "{0}"'
                                          .format(typ))
            for dt, result in dv.items():
                assert dt in self.all_data[typ], ('data["{0}"] contains extra '
                                                  'key "{1}"'.format(typ, dt))
                try:
                    expected = self.data[typ][dt]
                except KeyError:
                    continue

                # use a specific comparator
                # if available
                comparator = getattr(
                    self, "compare_{typ}_{dt}".format(typ=typ, dt=dt), None)
                if comparator is not None:
                    comparator(result, expected, typ, version)
                else:
                    check_arbitrary(result, expected)

        return data
Esempio n. 2
0
    def test_string_io(self):

        df = DataFrame(np.random.randn(10,2))
        s = df.to_msgpack(None)
        result = read_msgpack(s)
        tm.assert_frame_equal(result,df)

        s = df.to_msgpack()
        result = read_msgpack(s)
        tm.assert_frame_equal(result,df)

        s = df.to_msgpack()
        result = read_msgpack(compat.BytesIO(s))
        tm.assert_frame_equal(result,df)

        s = to_msgpack(None,df)
        result = read_msgpack(s)
        tm.assert_frame_equal(result, df)

        with ensure_clean(self.path) as p:

            s = df.to_msgpack()
            fh = open(p,'wb')
            fh.write(s)
            fh.close()
            result = read_msgpack(p)
            tm.assert_frame_equal(result, df)
Esempio n. 3
0
    def compare(self, current_data, all_data, vf, version):
        # GH12277 encoding default used to be latin-1, now utf-8
        if LooseVersion(version) < LooseVersion('0.18.0'):
            data = read_msgpack(vf, encoding='latin-1')
        else:
            data = read_msgpack(vf)

        if "panel" in data:
            # FIXME: kludge; get the key out of the stored file
            del data["panel"]

        self.check_min_structure(data, version)
        for typ, dv in data.items():
            assert typ in all_data, ('unpacked data contains '
                                     'extra key "{0}"'
                                     .format(typ))
            for dt, result in dv.items():
                assert dt in current_data[typ], ('data["{0}"] contains extra '
                                                 'key "{1}"'.format(typ, dt))
                try:
                    expected = current_data[typ][dt]
                except KeyError:
                    continue

                # use a specific comparator
                # if available
                comp_method = "compare_{typ}_{dt}".format(typ=typ, dt=dt)
                comparator = getattr(self, comp_method, None)
                if comparator is not None:
                    comparator(result, expected, typ, version)
                else:
                    check_arbitrary(result, expected)

        return data
Esempio n. 4
0
    def test_iterator_with_string_io(self):

        dfs = [ DataFrame(np.random.randn(10,2)) for i in range(5) ]
        s = to_msgpack(None,*dfs)
        for i, result in enumerate(read_msgpack(s.getvalue(),iterator=True)):
            tm.assert_frame_equal(result,dfs[i])

        s = to_msgpack(None,*dfs)
        for i, result in enumerate(read_msgpack(s,iterator=True)):
            tm.assert_frame_equal(result,dfs[i])
Esempio n. 5
0
    def test_iterator(self):

        l = [self.frame["float"], self.frame["float"].A, self.frame["float"].B, None]

        with ensure_clean(self.path) as path:
            to_msgpack(path, *l)
            for i, packed in enumerate(read_msgpack(path, iterator=True)):
                check_arbitrary(packed, l[i])
Esempio n. 6
0
    def test_iterator(self):

        packed_items = [self.frame['float'], self.frame['float'].A,
                        self.frame['float'].B, None]

        with ensure_clean(self.path) as path:
            to_msgpack(path, *packed_items)
            for i, packed in enumerate(read_msgpack(path, iterator=True)):
                check_arbitrary(packed, packed_items[i])
Esempio n. 7
0
    def compare(self, vf):
        data = read_msgpack(vf)
        for typ, dv in data.items():
            for dt, result in dv.items():
                try:
                    expected = self.data[typ][dt]
                except KeyError:
                    continue
                check_arbitrary(result, expected)

        return data
Esempio n. 8
0
    def compare(self, vf):
        data = read_msgpack(vf)
        self.check_min_structure(data)
        for typ, dv in data.items():
            assert typ in self.all_data, 'unpacked data contains extra key "{0}"'.format(typ)
            for dt, result in dv.items():
                assert dt in self.all_data[typ], 'data["{0}"] contains extra key "{1}"'.format(typ, dt)
                try:
                    expected = self.data[typ][dt]
                except KeyError:
                    continue
                check_arbitrary(result, expected)

        return data
Esempio n. 9
0
    def test_invalid_arg(self):
        # GH10369
        class A:

            def __init__(self):
                self.read = 0

        msg = "Invalid file path or buffer object type: <class '{}'>"
        with pytest.raises(ValueError, match=msg.format('NoneType')):
            read_msgpack(path_or_buf=None)
        with pytest.raises(ValueError, match=msg.format('dict')):
            read_msgpack(path_or_buf={})
        with pytest.raises(ValueError, match=msg.format(r'.*\.A')):
            read_msgpack(path_or_buf=A())
Esempio n. 10
0
    def compare(self, vf, version):
        data = read_msgpack(vf)
        self.check_min_structure(data)
        for typ, dv in data.items():
            assert typ in self.all_data, 'unpacked data contains extra key "{0}"'.format(typ)
            for dt, result in dv.items():
                assert dt in self.all_data[typ], 'data["{0}"] contains extra key "{1}"'.format(typ, dt)
                try:
                    expected = self.data[typ][dt]
                except KeyError:
                    continue

                # use a specific comparator
                # if available
                comparator = getattr(self,"compare_{typ}_{dt}".format(typ=typ,dt=dt), None)
                if comparator is not None:
                    comparator(result, expected, typ, version)
                else:
                    check_arbitrary(result, expected)

        return data
Esempio n. 11
0
 def encode_decode(self, x, compress=None, **kwargs):
     with ensure_clean(self.path) as p:
         to_msgpack(p, x, compress=compress, **kwargs)
         return read_msgpack(p, **kwargs)
Esempio n. 12
0
 def test_msgpack_period_freq(self):
     # https://github.com/pandas-dev/pandas/issues/24135
     s = Series(np.random.rand(5), index=date_range('20130101', periods=5))
     r = read_msgpack(s.to_msgpack())
     repr(r)
Esempio n. 13
0
 def encode_decode(self, x, compress=None, **kwargs):
     with ensure_clean(self.path) as p:
         to_msgpack(p, x, compress=compress, **kwargs)
         return read_msgpack(p, **kwargs)
Esempio n. 14
0
    def test_iterator_with_string_io(self):

        dfs = [DataFrame(np.random.randn(10, 2)) for i in range(5)]
        s = to_msgpack(None, *dfs)
        for i, result in enumerate(read_msgpack(s, iterator=True)):
            tm.assert_frame_equal(result, dfs[i])
Esempio n. 15
0
 def test_msgpack_period_freq(self):
     # https://github.com/pandas-dev/pandas/issues/24135
     s = Series(np.random.rand(5), index=date_range('20130101', periods=5))
     r = read_msgpack(s.to_msgpack())
     repr(r)