Skip to content

Commit 04de686

Browse files
committed
Bugfix for issue astropy#4104
1 parent 33298a1 commit 04de686

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎astropy/units/core.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ def is_final_result(unit):
11151115
return [self]
11161116

11171117
def compose(self, equivalencies=[], units=None, max_depth=2,
1118-
include_prefix_units=False):
1118+
include_prefix_units=None):
11191119
"""
11201120
Return the simplest possible composite unit(s) that represent
11211121
the given unit. Since there may be multiple equally simple
@@ -1151,6 +1151,9 @@ def compose(self, equivalencies=[], units=None, max_depth=2,
11511151
automatically determine which of the candidates are
11521152
better.
11531153
"""
1154+
if include_prefix_units is None:
1155+
include_prefix_units = units is not None
1156+
11541157
# Pre-normalize the equivalencies list
11551158
equivalencies = self._normalize_equivalencies(equivalencies)
11561159

‎astropy/units/tests/test_units.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ def test_units_manipulation():
128128
(u.AA * u.erg) ** 9
129129

130130

131+
def test_compose():
132+
x = u.m.compose(units=[u.m])
133+
assert x[0].to_string() == 'm'
134+
x = u.m.compose(units=[u.km], include_prefix_units=True)
135+
assert x[0].to_string() == '0.001 km'
136+
x = u.m.compose(units=[u.km])
137+
assert x[0].to_string() == '0.001 km'
138+
139+
131140
def test_decompose():
132141
assert u.Ry == u.Ry.decompose()
133142

0 commit comments

Comments
 (0)