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

Update lib.py #1162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update lib.py #1162

wants to merge 1 commit into from

Conversation

gitctrlx
Copy link

@gitctrlx gitctrlx commented Aug 1, 2024

Replacing pd.DataFrame with Generator[pd.DataFrame, None, None] The reason for replacing pd.DataFrame with Generator[pd.DataFrame, None, None] is to better reflect the actual output type of the random_ohlc_data function. Here are the specific reasons and benefits:

Reasons:
Accuracy of Output Type: The original code declared that the function returns a pd.DataFrame, but in reality, the function is a generator that yields multiple pd.DataFrame objects. Using Generator more accurately describes the function's behavior. Clarity of Type Hinting: Using Generator allows the code readers and users to more easily understand that the function returns a generator rather than a single DataFrame. This helps prevent potential misunderstandings and misuse.

Benefits:
Performance Improvement: Generators can generate data on-demand rather than generating all data at once, saving memory and improving performance, especially when dealing with large datasets. Lazy Evaluation: Generators allow for lazy evaluation, meaning data frames are only generated when needed. This can improve the efficiency and responsiveness of the code. Better Code Maintainability: Explicitly using generators makes the intent of the code clearer, enhancing readability and maintainability, making it easier for other developers to understand and maintain the code.

Replacing pd.DataFrame with Generator[pd.DataFrame, None, None]
The reason for replacing pd.DataFrame with Generator[pd.DataFrame, None, None] is to better reflect the actual output type of the random_ohlc_data function. Here are the specific reasons and benefits:

Reasons:
Accuracy of Output Type: The original code declared that the function returns a pd.DataFrame, but in reality, the function is a generator that yields multiple pd.DataFrame objects. Using Generator more accurately describes the function's behavior.
Clarity of Type Hinting: Using Generator allows the code readers and users to more easily understand that the function returns a generator rather than a single DataFrame. This helps prevent potential misunderstandings and misuse.
Benefits:
Performance Improvement: Generators can generate data on-demand rather than generating all data at once, saving memory and improving performance, especially when dealing with large datasets.
Lazy Evaluation: Generators allow for lazy evaluation, meaning data frames are only generated when needed. This can improve the efficiency and responsiveness of the code.
Better Code Maintainability: Explicitly using generators makes the intent of the code clearer, enhancing readability and maintainability, making it easier for other developers to understand and maintain the code.
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.

1 participant