Skip to content

Commit c7d7d36

Browse files
committed
fix for comments & test for compute.use_* options
1 parent aad3846 commit c7d7d36

File tree

8 files changed

+62
-8
lines changed

8 files changed

+62
-8
lines changed

doc/source/basics.rst

+10-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Accelerated operations
9393
----------------------
9494

9595
pandas has support for accelerating certain types of binary numerical and boolean operations using
96-
the ``numexpr`` library (starting in 0.11.0) and the ``bottleneck`` libraries.
96+
the ``numexpr`` library and the ``bottleneck`` libraries.
9797

9898
These libraries are especially useful when dealing with large data sets, and provide large
9999
speedups. ``numexpr`` uses smart chunking, caching, and multiple cores. ``bottleneck`` is
@@ -114,6 +114,15 @@ Here is a sample (using 100 column x 100,000 row ``DataFrames``):
114114
You are highly encouraged to install both libraries. See the section
115115
:ref:`Recommended Dependencies <install.recommended_dependencies>` for more installation info.
116116

117+
These are both enabled to be used by default, you can control this by setting the options:
118+
119+
.. versionadded:: 0.20.0
120+
121+
.. code-block:: python
122+
123+
pd.set_option('use_bottleneck', False)
124+
pd.set_option('use_numexpr', False)
125+
117126
.. _basics.binop:
118127

119128
Flexible binary operations

doc/source/options.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ mode.use_inf_as_null False True means treat None, NaN, -IN
426426
None and NaN are null, but INF, -INF
427427
are not null (new way).
428428
compute.use_bottleneck True Use the bottleneck library to accelerate
429-
computation if its installed
429+
computation if it is installed
430430
compute.use_numexpr True Use the numexpr library to accelerate
431-
computation if its installed
431+
computation if it is installed
432432
=================================== ============ ==================================
433433

434434

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ Other Enhancements
521521
- The ``display.show_dimensions`` option can now also be used to specify
522522
whether the length of a ``Series`` should be shown in its repr (:issue:`7117`).
523523
- ``parallel_coordinates()`` has gained a ``sort_labels`` keyword arg that sorts class labels and the colours assigned to them (:issue:`15908`)
524+
- Options added to allow one to turn on/off using ``bottleneck`` and ``numexpr``, see :ref:`here <basics.accelerate>` (:issue:`16157`)
524525

525526

526527
.. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations

pandas/core/computation/expressions.py

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def set_use_numexpr(v=True):
3636
global _USE_NUMEXPR
3737
if _NUMEXPR_INSTALLED:
3838
_USE_NUMEXPR = v
39+
elif v:
40+
warnings.warn("trying to set the option to use numexpr, "
41+
"but it is not installed!")
3942

4043
# choose what we are going to do
4144
global _evaluate, _where

pandas/core/config_init.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
use_bottleneck_doc = """
2323
: bool
24-
Use the bottleneck library to accelerate if its installed, default is True
24+
Use the bottleneck library to accelerate if it is installed,
25+
the default is True
2526
Valid values: False,True
2627
"""
2728

@@ -33,8 +34,8 @@ def use_bottleneck_cb(key):
3334

3435
use_numexpr_doc = """
3536
: bool
36-
Use the numexpr library to accelerate computation if its installed,
37-
default is True
37+
Use the numexpr library to accelerate computation if it is installed,
38+
the default is True
3839
Valid values: False,True
3940
"""
4041

pandas/core/nanops.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import itertools
22
import functools
3-
import numpy as np
43
import operator
4+
import warnings
55

6+
import numpy as np
67
from pandas import compat
78
from pandas._libs import tslib, algos, lib
89
from pandas.core.dtypes.common import (
@@ -34,6 +35,9 @@ def set_use_bottleneck(v=True):
3435
global _USE_BOTTLENECK
3536
if _BOTTLENECK_INSTALLED:
3637
_USE_BOTTLENECK = v
38+
elif v:
39+
warnings.warn("trying to set the option to use bottleneck, "
40+
"but it is not installed!")
3741

3842

3943
set_use_bottleneck(get_option('compute.use_bottleneck'))

pandas/tests/computation/test_compat.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pandas.core.computation.engines import _engines
77
import pandas.core.computation.expr as expr
88
from pandas.core.computation import _MIN_NUMEXPR_VERSION
9+
from pandas.util import testing as tm
910

1011

1112
def test_compat():
@@ -20,7 +21,15 @@ def test_compat():
2021
else:
2122
assert _NUMEXPR_INSTALLED
2223
except ImportError:
23-
pytest.skip("not testing numexpr version compat")
24+
# test the option of setting
25+
26+
# ok
27+
pd.set_option('use_numexpr', False)
28+
29+
# warn
30+
with tm.assert_produces_warning(
31+
UserWarning, check_stacklevel=False):
32+
pd.set_option('use_numexpr', True)
2433

2534

2635
@pytest.mark.parametrize('engine', _engines)

pandas/tests/test_nanops.py

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import warnings
99
import numpy as np
10+
11+
import pandas as pd
1012
from pandas import Series, isnull, _np_version_under1p9
1113
from pandas.core.dtypes.common import is_integer_dtype
1214
import pandas.core.nanops as nanops
@@ -1003,3 +1005,28 @@ def test_nans_skipna(self):
10031005
@property
10041006
def prng(self):
10051007
return np.random.RandomState(1234)
1008+
1009+
1010+
def test_use_bottleneck():
1011+
1012+
if nanops._BOTTLENECK_INSTALLED:
1013+
1014+
pd.set_option('use_bottleneck', True)
1015+
assert pd.get_option('use_bottleneck')
1016+
1017+
pd.set_option('use_bottleneck', False)
1018+
assert not pd.get_option('use_bottleneck')
1019+
1020+
pd.set_option('use_bottleneck', use_bn)
1021+
1022+
else:
1023+
1024+
# test the option of setting
1025+
1026+
# ok
1027+
pd.set_option('use_bottleneck', False)
1028+
1029+
# warn
1030+
with tm.assert_produces_warning(
1031+
UserWarning, check_stacklevel=False):
1032+
pd.set_option('use_bottleneck', True)

0 commit comments

Comments
 (0)