Skip to content

Commit

Permalink
fix type comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
mcw92 committed Aug 14, 2024
1 parent b1b967a commit 22a4d37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions propulate/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def __getitem__(self, key: str) -> Union[float, int, str]:
return self.mapping[key]
else:
# continuous variable
if self.types[key] == float:
if self.types[key] is float:
return float(self.position[self.offsets[key]].item())
elif self.types[key] == int:
elif self.types[key] is int:
return int(np.rint(self.position[self.offsets[key]]).item())
elif self.types[key] == str:
elif self.types[key] is str:
offset = self.offsets[key]
upper = self.offsets[key] + len(self.limits[key])
return str(
Expand All @@ -120,13 +120,13 @@ def __setitem__(self, key: str, newvalue: Union[float, int, str, Any]) -> None:
else:
if key not in self.limits:
raise ValueError("Unknown gene.")
if self.types[key] == float:
if self.types[key] is float:
assert isinstance(newvalue, float)
self.position[self.offsets[key]] = newvalue
elif self.types[key] == int:
elif self.types[key] is int:
assert isinstance(newvalue, int)
self.position[self.offsets[key]] = float(newvalue)
elif self.types[key] == str:
elif self.types[key] is str:
assert newvalue in self.limits[key]
offset = self.offsets[key]
upper = len(self.limits[key])
Expand Down

0 comments on commit 22a4d37

Please sign in to comment.