Repository: astropy/astropy

Issue:
Quantity(column_with_log_unit, subok=True) should work
As found in #8424, the following does not currently work:
```
from astropy.table import Column
from astropy import units as u

c = Column([1.,2.,3.], unit=u.dex(u.AA))
u.Quantity(c, subok=True)
# UnitTypeError: Quantity instances require <class 'astropy.units.core.UnitBase'> units, not <class 'astropy.units.function.logarithmic.DexUnit'> instances.
u.Quantity(c, c.unit, subok=True)
# <Dex [1., 2., 3.] dex(Angstrom)>
```
There doesn't seem to be a reason for this to happen. Likely all that is needed is to move the `subok` test from early on to a little later, after getting a possible unit from `value` (might also be possible to do this more automatically by using `cls.new_view` instead of taking `.view(cls)`) 

Discussion:
adrn: Sorry for missing this — looks fine to me, once you rebase for the silly changelog conflict!
mhvk: OK, rebased, and also got rid of a duplicate entry in `CHANGES.rst` (likely from another rebase...)
mhvk: And rebased again - sigh - though I think it was my own PR that made it necessary.

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 9054d21db2..93d04f1d59 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -69,7 +69,6 @@ astropy.modeling
 - Significant reorganization of the documentation. [#9078, #9171]
 
 - Add ``Tabular1D.inverse`` [#9083]
-- Significant reorganization of the documentation. [#9078, #9171]
 
 - ``Model.rename`` was changed to add the ability to rename ``Model.inputs``
   and ``Model.outputs``. [#9220]
@@ -562,6 +561,9 @@ astropy.units
 - Ensure that output from test functions of and comparisons between quantities
   can be stored into pre-allocated output arrays (using ``out=array``) [#9273]
 
+- Allow conversion of ``Column`` with logarithmic units to a suitable ``Quantity``
+  subclass if ``subok=True``. [#9188]
+
 astropy.utils
 ^^^^^^^^^^^^^
 
diff --git a/astropy/units/quantity.py b/astropy/units/quantity.py
index 51fccbee3d..596f97f3c2 100644
--- a/astropy/units/quantity.py
+++ b/astropy/units/quantity.py
@@ -279,11 +279,6 @@ class Quantity(np.ndarray):
         if unit is not None:
             # convert unit first, to avoid multiple string->unit conversions
             unit = Unit(unit)
-            # if we allow subclasses, allow a class from the unit.
-            if subok:
-                qcls = getattr(unit, '_quantity_class', cls)
-                if issubclass(qcls, cls):
-                    cls = qcls
 
         # optimize speed for Quantity with no dtype given, copy=False
         if isinstance(value, Quantity):
@@ -383,6 +378,12 @@ class Quantity(np.ndarray):
         if dtype is None and value.dtype.kind in 'iuO':
             value = value.astype(float)
 
+        # if we allow subclasses, allow a class from the unit.
+        if subok:
+            qcls = getattr(unit, '_quantity_class', cls)
+            if issubclass(qcls, cls):
+                cls = qcls
+
         value = value.view(cls)
         value._set_unit(value_unit)
         if unit is value_unit:


Test patch:
diff --git a/astropy/units/tests/test_quantity.py b/astropy/units/tests/test_quantity.py
index dabe380b35..ebc4108ad6 100644
--- a/astropy/units/tests/test_quantity.py
+++ b/astropy/units/tests/test_quantity.py
@@ -1420,6 +1420,20 @@ def test_quantity_from_table():
     assert qbp.unit == u.pc
     assert_array_equal(qbp.value, t['b'])
 
+    # Also check with a function unit (regression test for gh-8430)
+    t['a'].unit = u.dex(u.cm/u.s**2)
+    fq = u.Dex(t['a'])
+    assert fq.unit == u.dex(u.cm/u.s**2)
+    assert_array_equal(fq.value, t['a'])
+
+    fq2 = u.Quantity(t['a'], subok=True)
+    assert isinstance(fq2, u.Dex)
+    assert fq2.unit == u.dex(u.cm/u.s**2)
+    assert_array_equal(fq2.value, t['a'])
+
+    with pytest.raises(u.UnitTypeError):
+        u.Quantity(t['a'])
+
 
 def test_assign_slice_with_quantity_like():
     # Regression tests for gh-5961
@@ -1607,3 +1621,16 @@ class TestQuantityMimics:
         q[8:] = mimic
         assert np.all(q[:8].value == np.arange(8.))
         assert np.all(q[8:].value == [100., 200.])
+
+    def test_mimic_function_unit(self):
+        mimic = QuantityMimic([1., 2.], u.dex(u.cm/u.s**2))
+        d = u.Dex(mimic)
+        assert isinstance(d, u.Dex)
+        assert d.unit == u.dex(u.cm/u.s**2)
+        assert np.all(d.value == [1., 2.])
+        q = u.Quantity(mimic, subok=True)
+        assert isinstance(q, u.Dex)
+        assert q.unit == u.dex(u.cm/u.s**2)
+        assert np.all(q.value == [1., 2.])
+        with pytest.raises(u.UnitTypeError):
+            u.Quantity(mimic)