From e56523069866eacadce5818fee7a3bc3f2668f54 Mon Sep 17 00:00:00 2001 From: John Zwinck Date: Wed, 15 Mar 2017 20:51:33 +0800 Subject: [PATCH 1/2] ENH: use constant f32 eps, not np.finfo() during import NumPy docs for `np.finfo()` say not to call it during import (at module scope). It's a relatively expensive call, and it modifies the GIL state. Now we just hard-code it, because it is always the value anyway. This avoids touching the GIL at import, which helps avoid deadlocks in practice. Closes #14641. --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 19b7771251da3..c80e8c34aa88f 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1852,7 +1852,7 @@ def _convert_key(self, key, is_setter=False): # 32-bit floating point machine epsilon -_eps = np.finfo('f4').eps +_eps = 1.1920929e-07 def length_of_indexer(indexer, target=None): From dadb97c6e3fa684466b4e1b89c66cad677d3da03 Mon Sep 17 00:00:00 2001 From: John Zwinck Date: Wed, 15 Mar 2017 22:37:20 +0800 Subject: [PATCH 2/2] DOC: mention #14641 in 0.20.0 whatsnew --- doc/source/whatsnew/v0.20.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 9c6f5d3e0596d..f0bfd6a86abc3 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -920,3 +920,4 @@ Bug Fixes - Bug in ``pd.melt()`` where passing a tuple value for ``value_vars`` caused a ``TypeError`` (:issue:`15348`) - Bug in ``.eval()`` which caused multiline evals to fail with local variables not on the first line (:issue:`15342`) - Bug in ``pd.read_msgpack`` which did not allow to load dataframe with an index of type ``CategoricalIndex`` (:issue:`15487`) +- Use of ``np.finfo()`` during `import pandas` removed to mitigate deadlock on Python GIL misuse (:issue:`14641`)