Skip to content

Commit 1a0dc15

Browse files
authored
Docstring changes for rescale and rescale_preferred
1 parent fa0b684 commit 1a0dc15

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

quantities/quantity.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ def units(self, units):
201201

202202
def rescale(self, units=None):
203203
"""
204-
Return a copy of the quantity converted to the specified units
204+
Return a copy of the quantity converted to the specified units.
205+
If `units` is `None`, an attempt will be made to rescale the quantity
206+
to preferred units (see `rescale_preferred`).
205207
"""
206208
if units is None:
207209
try:
@@ -223,6 +225,18 @@ def rescale(self, units=None):
223225
return Quantity(cf*self.magnitude, to_u)
224226

225227
def rescale_preferred(self):
228+
"""
229+
Return a copy of the quantity converted to the preferred units and scale.
230+
These will be identified from among the compatible units specified in the
231+
list PREFERRED in this module. For example, a voltage quantity might be
232+
converted to `mV`:
233+
```
234+
import quantities as pq
235+
pq.quantity.PREFERRED = [pq.mV, pq.pA]
236+
old = 3.1415 * pq.V
237+
new = old.rescale_preferred() # `new` will be 3141.5 mV.
238+
```
239+
"""
226240
units_str = str(self.simplified.dimensionality)
227241
for preferred in PREFERRED:
228242
if units_str == str(preferred.simplified.dimensionality):

0 commit comments

Comments
 (0)