Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add extra config to make Unit model hashable #187

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

djs0109
Copy link
Contributor

@djs0109 djs0109 commented Mar 3, 2023

close #186

@djs0109 djs0109 linked an issue Mar 3, 2023 that may be closed by this pull request
@djs0109
Copy link
Contributor Author

djs0109 commented Mar 3, 2023

@tstorek I have made the changed you suggested in this branch, can you add a test for caching under test_units.py?

@tstorek tstorek changed the title chore: add extra config to make Unit model hashable fix: add extra config to make Unit model hashable May 31, 2023
@tstorek
Copy link
Collaborator

tstorek commented May 31, 2023

@djs0109 I added the test you requested. Including the example how lru_cache works ;) it raises perfomrance a lot with repeating function calls

@djs0109
Copy link
Contributor Author

djs0109 commented Jun 1, 2023

Thanks for providing this example 👍 I can see a speed boost of about 100-500 times

@djs0109 djs0109 requested a review from tstorek June 1, 2023 09:46
Copy link
Collaborator

@tstorek tstorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only minor things

CHANGELOG.md Outdated
@@ -1,3 +1,6 @@
#### v0.2.5
- fixed inconsistency of `entity_type` as required argument ([#188](https://github.com/RWTH-EBC/FiLiP/issues/188))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update before merge or do you autogenerate from here on? Probably better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! good point

@@ -1132,7 +1132,7 @@ def remove(self, v):
elif isinstance(v, SemanticIndividual):
self._set.remove(v.get_name())
else:
raise KeyError
raise KeyError(f"v is neither of type SemanticIndividual nor SemanticClass but {type(v)}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error use different code patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -64,7 +64,7 @@ def test_unit_model_caching(self):

self.assertEqual(unit.__hash__(), unit.__hash__())

@functools.lru_cache
@functools.lru_cache(maxsize=128)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that the default anyway? I don't think that python 3.7 should fail because of this. https://docs.python.org/3.7/library/functools.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder about that, but it actually fails with the error message:

TypeError: Expected maxsize to be an integer or None

btw, the python examples all give the maxsize explicitly.

@tstorek
Copy link
Collaborator

tstorek commented Jan 26, 2024

@djs0109 is this one fiex now? Probabably, we should double check by merging the main branch into it :)

@djs0109
Copy link
Contributor Author

djs0109 commented Jan 26, 2024

@tstorek it should have been fixed. But you are right, we should double check, because it is implemented before the pydantic migration. I will try to solve the conflict next week

# Conflicts:
#	CHANGELOG.md
#	filip/models/ngsi_v2/units.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make unit model hashable
2 participants