Repository: sympy/sympy

Issue:
Deprecated is_dimensionless when _collect_factor_and_dimension() is called
Malformed expression passed to _collect_factor_and_dimension() may cause deprecation warning:
```
\site-packages\sympy\physics\units\dimensions.py:284: SymPyDeprecationWarning:

wrong class has been deprecated since SymPy 1.2. See
https://github.com/sympy/sympy/issues/13336 for more info.

  feature="wrong class",
```

How to reproduce:
```
from sympy.physics import units
from sympy.physics.units import Quantity
from sympy.physics.units.systems.si import SI

def test_warning():
    V = Quantity('V')
    SI.set_quantity_dimension(V, units.volume)
    SI.set_quantity_scale_factor(V, 1 * units.liter)
    y = Quantity('y')
    SI.set_quantity_dimension(y, units.length)
    SI.set_quantity_scale_factor(y, 1 * units.meter)

    expr = V ** y
    quantity = SI._collect_factor_and_dimension(expr)
```

Discussion:

Patch:
diff --git a/sympy/physics/units/unitsystem.py b/sympy/physics/units/unitsystem.py
index d95c5b3284..24c67fdb66 100644
--- a/sympy/physics/units/unitsystem.py
+++ b/sympy/physics/units/unitsystem.py
@@ -178,7 +178,7 @@ def _collect_factor_and_dimension(self, expr):
         elif isinstance(expr, Pow):
             factor, dim = self._collect_factor_and_dimension(expr.base)
             exp_factor, exp_dim = self._collect_factor_and_dimension(expr.exp)
-            if exp_dim.is_dimensionless:
+            if self.get_dimension_system().is_dimensionless(exp_dim):
                 exp_dim = 1
             return factor ** exp_factor, dim ** (exp_factor * exp_dim)
         elif isinstance(expr, Add):


Test patch:
diff --git a/sympy/physics/units/tests/test_quantities.py b/sympy/physics/units/tests/test_quantities.py
index a08ac60ac0..b36913a3c2 100644
--- a/sympy/physics/units/tests/test_quantities.py
+++ b/sympy/physics/units/tests/test_quantities.py
@@ -1,3 +1,5 @@
+import warnings
+
 from sympy import (Abs, Add, Function, Number, Rational, S, Symbol,
                    diff, exp, integrate, log, sin, sqrt, symbols)
 from sympy.physics.units import (amount_of_substance, convert_to, find_unit,
@@ -484,3 +486,18 @@ def test_deprecated_quantity_methods():
         step.set_scale_factor(2*meter)
         assert convert_to(step, centimeter) == 200*centimeter
         assert convert_to(1000*step/second, kilometer/second) == 2*kilometer/second
+
+def test_issue_22164():
+    warnings.simplefilter("error")
+    dm = Quantity("dm")
+    SI.set_quantity_dimension(dm, length)
+    SI.set_quantity_scale_factor(dm, 1)
+
+    bad_exp = Quantity("bad_exp")
+    SI.set_quantity_dimension(bad_exp, length)
+    SI.set_quantity_scale_factor(bad_exp, 1)
+
+    expr = dm ** bad_exp
+
+    # deprecation warning is not expected here
+    SI._collect_factor_and_dimension(expr)