Repository: sympy/sympy
Pull request: Fix erroring test in `sympy/printing/tests/test_aesaracode.py`
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #24746 

#### Brief description of what is fixed or changed
Use Aesara `true_divide` function in place of deprecated `true_div`.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->


Problem statement:
`optional-dependencies` jobs in CI failing due to test error in `sympy/printing/tests/test_aesaracode.py`
Full traceback is:
```
____________ sympy/printing/tests/test_aesaracode.py:test_Rationals ____________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/testing/runtests.py", line 1337, in _timeout
    function()
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_aesaracode.py", line 267, in test_Rationals
    assert theq(aesara_code_(sy.Integer(2) / 3), aet.true_div(2, 3))
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_aesaracode.py", line 57, in aesara_code_
    return aesara_code(expr, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/printing/aesaracode.py", line 347, in aesara_code
    return AesaraPrinter(cache=cache, settings={}).doprint(expr, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/printing/aesaracode.py", line 307, in doprint
    return self._print(expr, dtypes=dtypes, broadcastables=broadcastables)
  File "/home/runner/work/sympy/sympy/sympy/printing/printer.py", line 331, in _print
    return printmethod(expr, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/printing/aesaracode.py", line 241, in _print_Rational
    return aet.true_div(self._print(expr.p, **kwargs),
  File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/aesara/tensor/__init__.py", line 172, in __getattr__
    warn(msg, DeprecationWarning, stacklevel=2)
DeprecationWarning: `true_div` is deprecated; use `true_divide` or `divide` instead.
```

Hints from issue discussion:
This is currently causing multiple job failures in all CI.
Opened PR #24747 to fix.
Issue seems to stem from the use of `aesara.tensor.true_div` in the Aesara printer` as well as in the test, because this has been deprecated.
Interestingly, it doesn't seem to be erroring with pytest.
> Interestingly, it doesn't seem to be erroring with pytest.

With pytest warnings are collected and shown at the end. You can use `-Werror` to make warnings become errors under pytest:
https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html

Commit message: Fix typo in module name

Patch to review:
diff --git a/sympy/printing/aesaracode.py b/sympy/printing/aesaracode.py
index 1806a0721328..5f6fc2e56a19 100644
--- a/sympy/printing/aesaracode.py
+++ b/sympy/printing/aesaracode.py
@@ -17,6 +17,13 @@
     from aesara.tensor.elemwise import Elemwise
     from aesara.tensor.elemwise import DimShuffle
 
+    # `true_divide` replaced `true_div` in Aesara 2.8.11 (released 2023) to
+    # match NumPy
+    # XXX: Remove this when not needed to support older versions.
+    true_divide = getattr(aet, 'true_divide', None)
+    if true_divide is None:
+        true_divide = aet.true_div
+
     mapping = {
             sympy.Add: aet.add,
             sympy.Mul: aet.mul,
@@ -69,6 +76,8 @@
             sympy.Transpose: DimShuffle((False, False), [1, 0]),
     }
 
+    aesara_version = tuple(getattr(aesara, '__version__').split('.'))
+
 
 class AesaraPrinter(Printer):
     """ Code printer which creates Aesara symbolic expression graphs.
@@ -238,8 +247,8 @@ def _print_Piecewise(self, expr, **kwargs):
         return aet.switch(p_cond, p_e, p_remaining)
 
     def _print_Rational(self, expr, **kwargs):
-        return aet.true_div(self._print(expr.p, **kwargs),
-                            self._print(expr.q, **kwargs))
+        return true_divide(self._print(expr.p, **kwargs),
+                           self._print(expr.q, **kwargs))
 
     def _print_Integer(self, expr, **kwargs):
         return expr.p
diff --git a/sympy/printing/tests/test_aesaracode.py b/sympy/printing/tests/test_aesaracode.py
index d820b9fc97ed..21484626dce9 100644
--- a/sympy/printing/tests/test_aesaracode.py
+++ b/sympy/printing/tests/test_aesaracode.py
@@ -30,6 +30,8 @@
     from aesara.tensor.elemwise import Elemwise, DimShuffle
     from aesara.tensor.math import Dot
 
+    from sympy.printing.aesaracode import true_divide
+
     xt, yt, zt = [aet.scalar(name, 'floatX') for name in 'xyz']
     Xt, Yt, Zt = [aet.tensor('floatX', (False, False), name=n) for n in 'XYZ']
 else:
@@ -264,8 +266,8 @@ def test_MatAdd():
 
 
 def test_Rationals():
-    assert theq(aesara_code_(sy.Integer(2) / 3), aet.true_div(2, 3))
-    assert theq(aesara_code_(S.Half), aet.true_div(1, 2))
+    assert theq(aesara_code_(sy.Integer(2) / 3), true_divide(2, 3))
+    assert theq(aesara_code_(S.Half), true_divide(1, 2))
 
 def test_Integers():
     assert aesara_code_(sy.Integer(3)) == 3


Code review comments:
diff_hunk: @@ -69,6 +76,8 @@
             sympy.Transpose: DimShuffle((False, False), [1, 0]),
     }
 
+    aesara_version = tuple(getattr(aesara, '__version__').split('.'))
path: sympy/printing/aesaracode.py
text: @user1:
I guess we don't need this any more.

@author:
Good spot. Address in https://github.com/sympy/sympy/pull/24747/commits/72b658b0f8f70c78ba3d645a2dacfe3bbcbc6f90.