-
Notifications
You must be signed in to change notification settings - Fork 0
Add date comparison #15
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aed39ab
Add date comparison
mharoruiz 959dbb4
Add docstring to test
mharoruiz 765778d
Update fetch_allocations_holdings
mharoruiz 7d18a6b
black
mharoruiz 76c3daf
Temporarily disable logging
mharoruiz f6586db
black
mharoruiz 62d120d
Update read_announcements.py
mharoruiz 72e3e52
Bump version: 1.2.0 → 1.3.0
mharoruiz 9af189f
Update docstring
mharoruiz 48b08b0
Bump version: 1.2.0 → 1.3.0
mharoruiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ def read_tsv(url: str) -> pd.DataFrame: | |
| return pd.read_csv(url, delimiter="/t", engine="python") | ||
|
|
||
| except pd.errors.ParserError: | ||
| raise ValueError("SDR _data not available for this date") | ||
| raise ValueError("SDR data not available for this date") | ||
|
|
||
|
|
||
| def clean_df(df: pd.DataFrame) -> pd.DataFrame: | ||
|
|
@@ -94,16 +94,29 @@ def get_latest_allocations_holdings_date() -> tuple[int, int]: | |
|
|
||
|
|
||
| def fetch_allocations_holdings(date: tuple[int, int] | None = None) -> pd.DataFrame: | ||
| """Fetch SDR holdings and allocations data for a given date | ||
| """ | ||
| Fetch SDR holdings and allocations data for a given date. If date is not specified or exceeds the latest available | ||
| date, it fetches data for the latest date | ||
|
|
||
| Args: | ||
| date: The year and month to get allocations and holdings data for. e.g. (2024, 11) for November 2024. If None, the latest announcements released are fetched | ||
| date: The year and month to get allocations and holdings data for. e.g. (2024, 11) for November 2024. | ||
| If None, the latest announcements released are fetched | ||
|
|
||
| returns: | ||
| A dataframe with the SDR allocations and holdings data | ||
| """ | ||
|
|
||
| latest_date = get_latest_allocations_holdings_date() | ||
|
|
||
| if date is None: | ||
| date = get_latest_allocations_holdings_date() | ||
| date = latest_date | ||
| else: | ||
| date_obj = datetime(date[0], date[1], 1) | ||
| 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" | ||
|
||
| ) | ||
| date = latest_date | ||
|
|
||
| return get_holdings_and_allocations_data(*date) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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_holdingsfunction you temporarily disable logging. The functionality should be: