diff --git a/CHANGES.md b/CHANGES.md index 58fb9a5e..afa02a94 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,8 @@ The released versions correspond to PyPI releases. compatible, we cannot exclude that we missed some problems. * Under macOS, at test start a symlink `/tmp` to the actual temporary directory is now created in the fake filesystem. +* Patching of parsers for pandas >= 1.2 is removed since pandas now uses Python fs functions + internally even when the engine selected is "c". ### Features * added possibility to set a path inaccessible under Windows by using `chown()` with diff --git a/pyfakefs/patched_packages.py b/pyfakefs/patched_packages.py index 88230b85..ba1a26b5 100644 --- a/pyfakefs/patched_packages.py +++ b/pyfakefs/patched_packages.py @@ -17,6 +17,7 @@ import sys try: + import pandas as pd import pandas.io.parsers as parsers except ImportError: parsers = None @@ -31,6 +32,14 @@ except ImportError: locks = None +# From pandas v 1.2 onwards the python fs functions are used even when the engine +# selected is "c". This means that we don't explicitly have to change the engine. +patch_pandas = parsers is not None and [int(v) for v in pd.__version__.split(".")] < [ + 1, + 2, + 0, +] + def get_modules_to_patch(): modules_to_patch = {} @@ -43,14 +52,14 @@ def get_modules_to_patch(): def get_classes_to_patch(): classes_to_patch = {} - if parsers is not None: + if patch_pandas: classes_to_patch["TextFileReader"] = "pandas.io.parsers" return classes_to_patch def get_fake_module_classes(): fake_module_classes = {} - if parsers is not None: + if patch_pandas: fake_module_classes["TextFileReader"] = FakeTextFileReader return fake_module_classes @@ -94,7 +103,7 @@ def __getattr__(self, name): return getattr(self._xlrd_module, name) -if parsers is not None: +if patch_pandas: # we currently need to add fake modules for both the parser module and # the contained text reader - maybe this can be simplified