Skip to content

Commit 4513cb7

Browse files
committed
Tweak
1 parent 6e063f8 commit 4513cb7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/pandas_openscm/unit_conversion.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from pandas_openscm.exceptions import MissingOptionalDependencyError
1313
from pandas_openscm.index_manipulation import set_index_levels_func
14-
from pandas_openscm.indexing import multi_index_match
14+
from pandas_openscm.indexing import multi_index_lookup, multi_index_match
1515

1616
if TYPE_CHECKING:
1717
import pint.facets
@@ -107,10 +107,14 @@ def convert_unit_from_target_series(
107107
df_reset_unit = df.reset_index(unit_level)
108108
df_units = df_reset_unit[unit_level].rename("df_unit")
109109

110+
desired_unit_in_df = multi_index_lookup(desired_unit, df_units.index).rename(
111+
"target_unit"
112+
)
113+
110114
# Don't need to align, pandas does that for us.
111115
# If you want to check, compare the below with
112116
# unit_map = pd.DataFrame([df_units_s, target_units_s.sample(frac=1)]).T
113-
unit_map = pd.DataFrame([df_units, desired_unit.rename("target_unit")]).T
117+
unit_map = pd.DataFrame([df_units, desired_unit_in_df]).T
114118

115119
unit_map_no_change = unit_map["df_unit"] == unit_map["target_unit"]
116120
if unit_map_no_change.all():

0 commit comments

Comments
 (0)