Skip to content

Commit 625ce42

Browse files
committed
Key units on strings to avoid Astropy bug
1 parent 8da19e1 commit 625ce42

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/opencosmo/units/converters.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ def constructor(x):
103103
return unit
104104
power = u_base.powers[index]
105105
new_unit = u_base / cu.littleh**power
106-
# There's a bug in astropy here, work around
107-
if len(new_unit.powers) == 1 and new_unit.powers[0] == 1:
108-
new_unit = new_unit.bases[0]
109106

110107
return new_unit
111108

src/opencosmo/units/handler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def with_conversions(
122122

123123
self.verify_conversions(columns, self.__current_convention)
124124
new_column_conversions = self.__column_conversions | columns
125-
new_conversions = self.__conversions | conversions
125+
new_conversions = self.__conversions | {
126+
str(key): value for key, value in conversions.items()
127+
}
126128
return UnitHandler(
127129
self.__base_convention,
128130
self.__current_convention,
@@ -155,7 +157,7 @@ def apply_units(self, data: dict[str, np.ndarray], unit_kwargs):
155157
unitful_value = applicator.apply(
156158
value, self.__current_convention, unit_kwargs=unit_kwargs
157159
)
158-
unit_conversion = self.__conversions.get(unitful_value.unit)
160+
unit_conversion = self.__conversions.get(str(unitful_value.unit))
159161
if unit_conversion is not None and column_conversion is None:
160162
unitful_value = unitful_value.to(unit_conversion)
161163
elif column_conversion is not None:

0 commit comments

Comments
 (0)