Skip to content

Add date comparison#15

Merged
mharoruiz merged 10 commits intomainfrom
12-bug-sdr-allocations-and-holdings-data
Feb 6, 2025
Merged

Add date comparison#15
mharoruiz merged 10 commits intomainfrom
12-bug-sdr-allocations-and-holdings-data

Conversation

@mharoruiz
Copy link
Collaborator

Added a date comparison to fetch_allocations_holdings() when no date is provided to make sure the output reflects the latest date available if the provided one is further in the future.

@mharoruiz mharoruiz linked an issue Jan 31, 2025 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.11%. Comparing base (662d05d) to head (48b08b0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   93.95%   94.11%   +0.15%     
==========================================
  Files          12       12              
  Lines         331      340       +9     
==========================================
+ Hits          311      320       +9     
  Misses         20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mharoruiz mharoruiz requested a review from lpicci96 January 31, 2025 15:46
Copy link
Collaborator

@lpicci96 lpicci96 left a comment

Choose a reason for hiding this comment

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

Thanks @mharoruiz
2 changes I think we should make

latest_date_obj = datetime(latest_date[0], latest_date[1], 1)
if date_obj > latest_date_obj:
logger.info(
f"SDR data unavailable for date: {format_date(date[1],date[0])}. Will fetch latest available"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we should return data as this might lead to silent errors. It might be better to raise a value error noting data for the date is unavailable, and specify the latest available date

A dataframe with the SDR allocations and holdings data
"""

latest_date = get_latest_allocations_holdings_date()
Copy link
Collaborator

Choose a reason for hiding this comment

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

A minor issue. This function logs a message saying it is retrieving the latest date. This doesn't make sense when a user requests a specific date.

Copy link
Collaborator Author

@mharoruiz mharoruiz Feb 4, 2025

Choose a reason for hiding this comment

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

I added a boolean option to suppress the logging info in get_latest_allocations_holdings_date(). Not sure if this is the best workaround though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is the best approach, because it isn't very useful argument for the user to be exposed to. I suggest within the fetch_allocations_holdings function you temporarily disable logging. The functionality should be:

  • if the user does not set a date or requests the latest date, it should log the message "fetching latest date"
  • if the user specifies the date, it should not log that message, only the "fetching data" message. To do this disable the logger before the fetch_latest_date function is called, then reset the logger after it is called

@mharoruiz mharoruiz requested a review from lpicci96 February 4, 2025 08:37

@lru_cache
def get_latest_allocations_holdings_date() -> tuple[int, int]:
def get_latest_allocations_holdings_date(log_info=True) -> tuple[int, int]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed, this should be called "fetch..." to be consistent with the other user facing functions

@mharoruiz mharoruiz requested a review from lpicci96 February 4, 2025 12:56
# Temporarily disable logging while calling fetch_latest_allocations_holdings_date()
logger.setLevel(logging.WARNING)
latest_date = fetch_latest_allocations_holdings_date()
logger.setLevel(logging.INFO)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This approach works. The only consideration is that you are hard coding the level back to INFO which is not the safest approach. You should rather catch what the original level was - something like original_level = logger.level and after completion of the task, set it back to original_level

@mharoruiz mharoruiz requested a review from lpicci96 February 5, 2025 16:39
@mharoruiz mharoruiz merged commit 87c63e8 into main Feb 6, 2025
6 checks passed
@mharoruiz mharoruiz deleted the 12-bug-sdr-allocations-and-holdings-data branch February 6, 2025 08:30
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.

BUG: sdr allocations and holdings data

3 participants