Fix Pandas >= 2.x compatibility issue in get_history() frequency generation#33
Open
JrryChen wants to merge 2 commits into
Open
Fix Pandas >= 2.x compatibility issue in get_history() frequency generation#33JrryChen wants to merge 2 commits into
JrryChen wants to merge 2 commits into
Conversation
Newer numpy versions use a lowercase "h" instead of "H". When trying to get smaller granular historical data like at 5 seconds, an error would occur:
ValueError: Invalid frequency: 6H. Failed to parse with error message: ValueError("Invalid frequency: H. Failed to parse with error message: KeyError('H'). Did you mean h?")
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes a compatibility issue with Pandas versions >= 2.x when calling get_history with second-based granularity (e.g. "S5").
In newer Pandas versions, uppercase time frequency aliases are no longer accepted when passed to pd.time_date() so the current implementation of batching frequencies into hourly segments when a user requests second-based granularity breaks, resulting in an error:
ValueError: Invalid frequency: 6H.
Failed to parse with error message:
ValueError("Invalid frequency: H. Failed to parse with error message: KeyError('H'). Did you mean h?")
This PR updates this freq string to use a lowercase "h" to be more in line with newer Pandas versions.
No other bugs were noticed beyond fixing this error.