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

How can I access the actual date and rate used when a fallback method is specified? #41

Open
rodrigogonegit opened this issue Sep 1, 2022 · 1 comment

Comments

@rodrigogonegit
Copy link

rodrigogonegit commented Sep 1, 2022

Hey, I have a particular use case in which I'd like to save the last known date and rate for unknown values, to keep as a reference as to what actual rate and date were used.

def _use_last_known(self, currency):
        """Fill missing rates of a currency.
        This is done by using the last known rate.
        :param str currency: The currency to fill missing rates for.
        """
        rates = self._rates[currency]

        for date in sorted(rates):
            rate = rates[date]
            if rate is not None:
                last_rate, last_date = rate, date
            else:
                rates[date] = last_rate
                if self.verbose:
                    print(
                        "{}: filling {} missing rate using {} from {}".format(
                            currency, date, last_rate, last_date
                        )
                    )

It seems the lib is simply disregarding this information atm. I'd be happy to do it myself, but how would you like it to be done?

@alexprengere
Copy link
Owner

Indeed this information is not kept. If I understand correctly, what you want is a new method that for each currency and date, returns the actual date used for the rate?

Something like:

def _get_rate_actual_date(self, currency, date):
    pass

A possible implementation would be to fill a self._rates_origin[currency][date] -> origin_date object with those data. We would need to either fill it will all dates, or only the cases where a fallback was done. Also both fallback methods would need to be changed.

I am not 100% sure this is needed, as this is the first time such use case is mentioned, and it would grow a bit the memory usage (also, it can be implemented in client code using subclassing).

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

No branches or pull requests

2 participants