From 248e6daf602cdc03bb84129f9df8338bf2c311a8 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Mon, 10 Sep 2018 07:30:45 +1000 Subject: [PATCH] Simplify copying of inputs --- scaling/froude.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scaling/froude.py b/scaling/froude.py index a8ee603..456f9bb 100644 --- a/scaling/froude.py +++ b/scaling/froude.py @@ -3,8 +3,6 @@ import pint def _convert(x, length_scale_factor, from_unit, to_unit): - x_scaled = x.copy() - # Initialise unit definitions ureg = pint.UnitRegistry() @@ -24,18 +22,18 @@ def _convert(x, length_scale_factor, from_unit, to_unit): from_unit.dimensionality['[time]'] * froude_t_exponent + from_unit.dimensionality['[mass]'] * froude_m_exponent) - # Scale time (dataframe only) - try: - x_scaled.index *= length_scale_factor**froude_t_exponent - except AttributeError: - pass - # Scale values - x_scaled *= froude_scale_factor + x_scaled = x * froude_scale_factor # Convert to output units x_scaled *= unit_conversion_factor + # Scale time (dataframe or series only) + try: + x_scaled.index *= length_scale_factor**froude_t_exponent + except (AttributeError, TypeError): + pass + return x_scaled