def write_graph(self, graph_object, graph_name='Graph', image_width=5.25):

        memfile = BytesIO()
        graph_object.get_figure().savefig(memfile)

        self.document.add_paragraph(graph_name, style='List Bullet')
        self.document.add_picture(memfile, width=Inches(image_width))
        self.document.save(self.docname)
        memfile.close()
Пример #2
0
 def test_stringio_writer(self):
     _skip_if_no_xlsxwriter()
     _skip_if_no_xlrd()
     
     path = BytesIO()
     with ExcelWriter(path, engine='xlsxwriter', **{'options': {'in-memory': True}}) as ew:
         self.frame.to_excel(ew, 'test1', engine='xlsxwriter')
         ew.save()
         path.seek(0)
         ef = ExcelFile(path)
         found_df = ef.parse('test1')
         tm.assert_frame_equal(self.frame, found_df)
     path.close()
Пример #3
0
    def test_utf16_bom_skiprows(self):
        # #2298
        data = u("""skip this
skip this too
A\tB\tC
1\t2\t3
4\t5\t6""")

        data2 = u("""skip this
skip this too
A,B,C
1,2,3
4,5,6""")

        path = '__%s__.csv' % tm.rands(10)

        with tm.ensure_clean(path) as path:
            for sep, dat in [('\t', data), (',', data2)]:
                for enc in ['utf-16', 'utf-16le', 'utf-16be']:
                    bytes = dat.encode(enc)
                    with open(path, 'wb') as f:
                        f.write(bytes)

                    s = BytesIO(dat.encode('utf-8'))
                    if compat.PY3:
                        # somewhat False since the code never sees bytes
                        from io import TextIOWrapper
                        s = TextIOWrapper(s, encoding='utf-8')

                    result = self.read_csv(path,
                                           encoding=enc,
                                           skiprows=2,
                                           sep=sep)
                    expected = self.read_csv(s,
                                             encoding='utf-8',
                                             skiprows=2,
                                             sep=sep)
                    s.close()

                    tm.assert_frame_equal(result, expected)
Пример #4
0
    def test_utf16_bom_skiprows(self):
        # #2298
        data = u(
            """skip this
skip this too
A\tB\tC
1\t2\t3
4\t5\t6"""
        )

        data2 = u(
            """skip this
skip this too
A,B,C
1,2,3
4,5,6"""
        )

        path = "__%s__.csv" % tm.rands(10)

        with tm.ensure_clean(path) as path:
            for sep, dat in [("\t", data), (",", data2)]:
                for enc in ["utf-16", "utf-16le", "utf-16be"]:
                    bytes = dat.encode(enc)
                    with open(path, "wb") as f:
                        f.write(bytes)

                    s = BytesIO(dat.encode("utf-8"))
                    if compat.PY3:
                        # somewhat False since the code never sees bytes
                        from io import TextIOWrapper

                        s = TextIOWrapper(s, encoding="utf-8")

                    result = self.read_csv(path, encoding=enc, skiprows=2, sep=sep)
                    expected = self.read_csv(s, encoding="utf-8", skiprows=2, sep=sep)
                    s.close()

                    tm.assert_frame_equal(result, expected)
Пример #5
0
 def add_fig(self, wid=6):
     memfile = BytesIO()
     plt.savefig(memfile)
     self.document.add_picture(memfile, width=Inches(wid))
     memfile.close()