Skip to content

Commit 2bfdc02

Browse files
authored
Remove engine overwrite in pandas TextFileReader patch (#791)
* remove patching of TextFileReader for pandas for version >= 1.2
1 parent 547c08a commit 2bfdc02

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The released versions correspond to PyPI releases.
1111
compatible, we cannot exclude that we missed some problems.
1212
* Under macOS, at test start a symlink `/tmp` to the actual temporary directory is
1313
now created in the fake filesystem.
14+
* Patching of parsers for pandas >= 1.2 is removed since pandas now uses Python fs functions
15+
internally even when the engine selected is "c".
1416

1517
### Features
1618
* added possibility to set a path inaccessible under Windows by using `chown()` with

pyfakefs/patched_packages.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sys
1818

1919
try:
20+
import pandas as pd
2021
import pandas.io.parsers as parsers
2122
except ImportError:
2223
parsers = None
@@ -31,6 +32,14 @@
3132
except ImportError:
3233
locks = None
3334

35+
# From pandas v 1.2 onwards the python fs functions are used even when the engine
36+
# selected is "c". This means that we don't explicitly have to change the engine.
37+
patch_pandas = parsers is not None and [int(v) for v in pd.__version__.split(".")] < [
38+
1,
39+
2,
40+
0,
41+
]
42+
3443

3544
def get_modules_to_patch():
3645
modules_to_patch = {}
@@ -43,14 +52,14 @@ def get_modules_to_patch():
4352

4453
def get_classes_to_patch():
4554
classes_to_patch = {}
46-
if parsers is not None:
55+
if patch_pandas:
4756
classes_to_patch["TextFileReader"] = "pandas.io.parsers"
4857
return classes_to_patch
4958

5059

5160
def get_fake_module_classes():
5261
fake_module_classes = {}
53-
if parsers is not None:
62+
if patch_pandas:
5463
fake_module_classes["TextFileReader"] = FakeTextFileReader
5564
return fake_module_classes
5665

@@ -94,7 +103,7 @@ def __getattr__(self, name):
94103
return getattr(self._xlrd_module, name)
95104

96105

97-
if parsers is not None:
106+
if patch_pandas:
98107
# we currently need to add fake modules for both the parser module and
99108
# the contained text reader - maybe this can be simplified
100109

0 commit comments

Comments
 (0)