Skip to content

Commit b1999ff

Browse files
committed
Deprecate LazyExpr.evaluate() for forthcoming 2.7.0
1 parent 8814dd8 commit b1999ff

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

blosc2/lazyexpr.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# This source code is licensed under a BSD-style license (found in the
66
# LICENSE file in the root directory of this source tree)
77
#######################################################################
8+
import warnings
9+
810
import ndindex
911
import numexpr as ne
1012
import numpy as np
@@ -218,9 +220,39 @@ def __rpow__(self, value):
218220
def __ipow__(self, value):
219221
return self.update_expr(new_op=(self, "**", value))
220222

223+
def evaluate(self, item=None, **kwargs) -> blosc2.NDArray:
224+
"""Evaluate the lazy expression in self.
221225
226+
Parameters
227+
----------
228+
item: slice, list of slices, optional
229+
If not None, only the chunks that intersect with the slices
230+
in items will be evaluated.
231+
kwargs: dict, optional
232+
Keyword arguments that are supported by the :func:`empty` constructor.
222233
223-
def evaluate(self, item=None, **kwargs) -> blosc2.NDArray:
234+
Returns
235+
-------
236+
:ref:`NDArray`
237+
The output array.
238+
239+
Note
240+
----
241+
242+
This is a deprecated method. Use the new evaluation engine in Python-Blosc2 3.x.
243+
"""
244+
warnings.warn(
245+
"The `evaluate` method is deprecated as of Python-Blosc2 2.7.0 and is"
246+
" actually removed in Python-Blosc2 3.x series. Use `LazyExpr.eval()` instead. "
247+
"If you are interested in computing expressions involving NDArray instances, "
248+
"please use the new, much improved, evaluation engine in Python-Blosc2 3.x series. "
249+
"For more information, please check the documentation at: <New 3.x documentation URL>",
250+
stacklevel=2,
251+
category=DeprecationWarning,
252+
)
253+
return self.eval(item=item, **kwargs)
254+
255+
def eval(self, item=None, **kwargs) -> blosc2.NDArray:
224256
"""Evaluate the lazy expression in self.
225257
226258
Parameters
@@ -235,6 +267,11 @@ def evaluate(self, item=None, **kwargs) -> blosc2.NDArray:
235267
-------
236268
:ref:`NDArray`
237269
The output array.
270+
271+
Note
272+
----
273+
274+
This is a deprecated method. Use the new evaluation engine in Python-Blosc2 3.x.
238275
"""
239276
shape, dtype, equal_chunks, equal_blocks = validate_inputs(self.operands)
240277
nelem = np.prod(shape)
@@ -249,7 +286,7 @@ def evaluate(self, item=None, **kwargs) -> blosc2.NDArray:
249286
return out
250287

251288
def __getitem__(self, item):
252-
ndarray = self.evaluate(item=item)
289+
ndarray = self.eval(item=item)
253290
return ndarray[item] if item is not None else ndarray[:]
254291

255292
def __str__(self):
@@ -475,7 +512,7 @@ def do_slices_intersect(slice1, slice2):
475512
print(f"Elapsed time (numexpr, [:]): {time() - t0:.3f} s")
476513
nres = nres[sl] if sl is not None else nres
477514
t0 = time()
478-
res = expr.evaluate(item=sl)
515+
res = expr.eval(item=sl)
479516
print(f"Elapsed time (evaluate): {time() - t0:.3f} s")
480517
res = res[sl] if sl is not None else res[:]
481518
t0 = time()
@@ -498,7 +535,7 @@ def do_slices_intersect(slice1, slice2):
498535
print(f"Elapsed time (numexpr, [:]): {time() - t0:.3f} s")
499536
nres = nres[sl] if sl is not None else nres
500537
t0 = time()
501-
res = expr.evaluate(sl)
538+
res = expr.eval(sl)
502539
print(f"Elapsed time (evaluate): {time() - t0:.3f} s")
503540
res = res[sl] if sl is not None else res[:]
504541
t0 = time()

tests/ndarray/test_lazyexpr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_simple_expression(array_fixture):
8585
a1, a2, a3, a4, na1, na2, na3, na4 = array_fixture
8686
expr = a1 + a2 - a3 * a4
8787
nres = ne.evaluate("na1 + na2 - na3 * na4")
88-
res = expr.evaluate()
88+
res = expr.eval()
8989
np.testing.assert_allclose(res[:], nres)
9090

9191

@@ -97,7 +97,7 @@ def test_iXXX(array_fixture):
9797
expr *= 2 # __imul__
9898
expr /= 7 # __itruediv__
9999
expr **= 2.3 # __ipow__
100-
res = expr.evaluate()
100+
res = expr.eval()
101101
nres = ne.evaluate("(((((na1 ** 3 + na2 ** 2 + na3 ** 3 - na4 + 3) + 5) - 15) * 2) / 7) ** 2.3")
102102
np.testing.assert_allclose(res[:], nres)
103103

@@ -107,7 +107,7 @@ def test_complex_evaluate(array_fixture):
107107
expr = blosc2.tan(a1) * (blosc2.sin(a2) * blosc2.sin(a2) + blosc2.cos(a3)) + (blosc2.sqrt(a4) * 2)
108108
expr += 2
109109
nres = ne.evaluate("tan(na1) * (sin(na2) * sin(na2) + cos(na3)) + (sqrt(na4) * 2) + 2")
110-
res = expr.evaluate()
110+
res = expr.eval()
111111
np.testing.assert_allclose(res[:], nres)
112112

113113

0 commit comments

Comments
 (0)