Skip to content

Commit adbfbcc

Browse files
committed
Documentation changes after review
- added test for writing excel file
1 parent 4286167 commit adbfbcc

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

docs/usage.rst

+16-15
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ want to set this to ``False``.
359359

360360
use_known_patches
361361
~~~~~~~~~~~~~~~~~
362-
If this is set to ``True`` (the default), ``pyfakefs`` patches some
363-
libraries that are known to not work out of the box, to be able to work with
364-
the fake filesystem. Currently, this includes patches for some ``pandas``
365-
read methods like ``read_csv`` and ``read_excel`` - more may follow. This
366-
flag is there to allow to disable this functionality in case it causes any
367-
problems. It may be removed or replaced by a more fine-grained argument in
368-
future releases.
369-
362+
Some libraries are known to require patching in order to work with pyfakefs.
363+
If ``use_known_patches`` is set to ``True`` (the default), pyfakefs patches
364+
these libraries so that they will work with the fake filesystem. Currently, this
365+
includes patches for ``pandas`` read methods like ``read_csv`` and
366+
``read_excel``--more may follow. Ordinarily, the default value of
367+
``use_known_patches`` should be used, but it is present to allow users to
368+
disable this patching in case it causes any problems. It may be removed or
369+
replaced by more fine-grained arguments in future releases.
370370

371371
Using convenience methods
372372
-------------------------
@@ -604,9 +604,9 @@ reasons:
604604
are more examples for patches that may be useful, we may add them in the
605605
documentation.
606606
- It uses C libraries to access the file system. There is no way no make
607-
such a module work with ``pyfakefs`` - if you want to use it, you have to
608-
patch the whole module. In some cases, a library implemented in Python with
609-
a similar interface already exists. An example is ``lxml``,
607+
such a module work with ``pyfakefs``--if you want to use it, you
608+
have to patch the whole module. In some cases, a library implemented in
609+
Python with a similar interface already exists. An example is ``lxml``,
610610
which can be substituted with ``ElementTree`` in most cases for testing.
611611
612612
A list of Python modules that are known to not work correctly with
@@ -618,10 +618,11 @@ A list of Python modules that are known to not work correctly with
618618
- the ``Pillow`` image library does not work with pyfakefs at least if writing
619619
JPEG files (see `this issue <https://github.com/jmcgeheeiv/pyfakefs/issues/529>`__)
620620
- ``pandas`` (the Python data analysis library) uses its own internal file
621-
system access, written in C, and does therefore not work with pyfakefs out
622-
of the box. ``pyfakefs`` adds some patches so that many of the
623-
``read_xxx`` functions will work with the fake system (including
624-
``read_csv`` and ``read_excel``).
621+
system access written in C. Thus much of ``pandas`` will not work with
622+
``pyfakefs``. Having said that, ``pyfakefs`` patches ``pandas`` so that many
623+
of the ``read_xxx`` functions, including ``read_csv`` and ``read_excel``,
624+
as well as some writer functions, do work with the fake file system. If
625+
you use only these functions, ``pyfakefs`` will work with ``pandas``.
625626
626627
If you are not sure if a module can be handled, or how to do it, you can
627628
always write a new issue, of course!

extra_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ scandir>=1.8
1616
# we use the latest version to see any problems with new versions
1717
pandas
1818
xlrd
19+
openpyxl

pyfakefs/tests/patched_packages_test.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_read_table(self):
4747
assert (df.columns == ['1', '2', '3', '4']).all()
4848

4949
if pd is not None and xlrd is not None:
50-
def test_load_excel(self):
50+
def test_read_excel(self):
5151
path = '/foo/bar.xlsx'
5252
src_path = os.path.dirname(os.path.abspath(__file__))
5353
src_path = os.path.join(src_path, 'fixtures', 'excel_test.xlsx')
@@ -56,3 +56,12 @@ def test_load_excel(self):
5656
self.fs.add_real_file(src_path, target_path=path)
5757
df = pd.read_excel(path)
5858
assert (df.columns == [1, 2, 3, 4]).all()
59+
60+
def test_write_excel(self):
61+
self.fs.create_dir('/foo')
62+
path = '/foo/bar.xlsx'
63+
df = pd.DataFrame([[0, 1, 2, 3]])
64+
with pd.ExcelWriter(path) as writer:
65+
df.to_excel(writer)
66+
df = pd.read_excel(path)
67+
assert (df.columns == ['Unnamed: 0', 0, 1, 2, 3]).all()

0 commit comments

Comments
 (0)