-
Notifications
You must be signed in to change notification settings - Fork 477
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
Dynamic contexts, currency conversion, and failing to find the shortest path #2146
Comments
Welcome and thanks for words about Pint. I think you are right. For the most of the graphs of units that I can think of BFS should be faster. Would you like to give it a try and if it works make a PR |
✅ Just put a PR together in #2147. |
Great, I will take a look. Do you have a benchmark? |
I don't have a benchmark, but I did add another unit test that is very slow without the improvement that mimics the situation I was in. |
This is the first time I have seen a robust way of setting up daily currency rates in bulk. Is this something worth adding to pint's documentation or potentially to pint itself or a pint-currency module? |
@andrewgsavage I really like this idea. We have received this question about currencies many times in the last years. |
First time poster, long-time fan of
pint
. Thank you.I'm currently working on a project where I use pint extensively for all kinds of unit conversions. We're working on incorporating a feature to allow for multiple types of currencies and I nearly have a working implementation that plays nicely with pint, but I've run into a strange bug. For reference, the relevant tidbit of the issue is captured in this gist.
When I'm only switching between a few currencies, I notice that it is able to successfully do the calculations without too much trouble. You can see this by running
poetry run python working.py
, the code is reproduced here for convenience:But when using all 42 currencies that are supported by currencyconverter as above, I notice that the conversion does not happen. When I KeyboardInterrupt, it appears to be stuck in a pint internal function that is related to the shortest path. Here is the output after running
poetry run python hanging.py
and then issuing a KeyboardInterrupt after ~5s:My best guess is that there is a gap in the shortest path algorithm that is being used to infer the unit conversion. I am specifying all pairwise conversions so there really shouldn't be any need for anything terribly fancy to infer the conversion path. Looking at the implementation of
util.find_shortest_path
, it made me wonder if a breadth first search approach would be more efficient.Thanks in advance for your help!
The text was updated successfully, but these errors were encountered: