Skip to content

feat: enhance timeline and waterfall plots with additional documentation #64

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 1 commit into from
Jul 20, 2024

Conversation

mvanwyk
Copy link
Contributor

@mvanwyk mvanwyk commented Jul 20, 2024

User description

…ion and features


PR Type

Enhancement, Documentation


Description

  • Added move_legend_outside parameter to time_plot function to allow legend positioning outside the plot.
  • Enhanced docstrings for time_plot and waterfall_plot functions with detailed descriptions, use cases, and examples.
  • Updated markdown documentation to include detailed explanations and example usage for time_plot and waterfall_plot.
  • Added markdown linting configuration to allow specific HTML elements and set line length.

Changes walkthrough 📝

Relevant files
Enhancement
standard_graphs.py
Enhance time_plot and waterfall_plot functions with new features and
documentation

pyretailscience/standard_graphs.py

  • Added move_legend_outside parameter to time_plot function.
  • Enhanced docstrings for time_plot and waterfall_plot functions with
    detailed descriptions and use cases.
  • Updated legend positioning logic in time_plot function.
  • +26/-0   
    Configuration changes
    .markdownlint.json
    Add markdown linting configuration                                             

    .markdownlint.json

  • Added markdown linting rules to allow specific HTML elements and set
    line length.
  • +4/-0     
    Documentation
    analysis_modules.md
    Update documentation for time_plot and waterfall_plot with examples

    docs/analysis_modules.md

  • Added detailed documentation for time_plot and waterfall_plot
    functions.
  • Included example usage and images for time_plot.
  • +51/-1   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Summary by CodeRabbit

    • New Features

      • Introduced a new configuration file for Markdown linting, enhancing formatting flexibility and line length standards.
      • Added a section on "Timeline Plot" in the documentation, detailing its applications and providing a sample code snippet.
    • Documentation

      • Expanded documentation for the time_plot function, including a new parameter for legend positioning and detailed use cases.
      • Enhanced the docstring for the waterfall_plot function to improve user understanding of its applications.

    Copy link

    coderabbitai bot commented Jul 20, 2024

    Walkthrough

    The recent updates introduce a new Markdown linting configuration, enhance documentation about timeline plots, and improve plotting functions within the codebase. Collectively, these changes foster better readability, usability, and user engagement, ensuring that both documentation and functions are more informative and aligned with project standards.

    Changes

    File Change Summary
    .markdownlint.json New Markdown linting configuration allowing <div> elements and setting a max line length.
    docs/analysis_modules.md Added a section on "Timeline Plot" with applications and an example code snippet; minor image path fix.
    pyretailscience/standard_graphs.py Enhanced time_plot and waterfall_plot functions with new parameters and expanded documentation.

    Poem

    In the garden of code, where changes bloom,
    A plot of time dances, dispelling the gloom.
    With rules to guide and docs that sing,
    We visualize data, oh what joy it brings!
    Hopping along, with every new line,
    Our project grows brighter, and all will be fine! 🐇✨


    Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

    Share
    Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>.
      • Generate unit testing code for this file.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai generate unit testing code for this file.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai generate interesting stats about this repository and render them as a table.
      • @coderabbitai show all the console.log statements in this repository.
      • @coderabbitai read src/utils.ts and generate unit testing code.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
      • @coderabbitai help me debug CodeRabbit configuration file.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (invoked as PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Documentation and Community

    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.

    @qodo-merge-pro qodo-merge-pro bot added documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3 labels Jul 20, 2024
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Documentation Clarity
    The added docstrings for the time_plot and waterfall_plot functions are very detailed and informative. However, it's important to ensure that the level of detail is consistent with the rest of the project's documentation standards. Overly verbose documentation might overwhelm users or detract from other parts of the documentation.

    Parameter Default
    The new parameter move_legend_outside defaults to True, which changes the default behavior of the time_plot function. Consider whether this change might affect existing users who upgrade to this version without expecting changes in the plot layout.

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a check for ax not being None before setting legend properties

    To ensure that the move_legend_outside parameter is used effectively, add a check to
    ensure that ax is not None before attempting to modify the legend properties. This
    prevents potential runtime errors when ax is not provided.

    pyretailscience/standard_graphs.py [104-105]

    -if move_legend_outside:
    +if ax is not None and move_legend_outside:
         legend_bbox_to_anchor = (1.05, 1)
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a check to ensure ax is not None before modifying legend properties prevents potential runtime errors. This is a significant improvement for robustness and reliability.

    8
    Maintainability
    Refactor the legend positioning logic into a separate function

    To improve readability and maintainability, consider refactoring the conditional
    logic for setting legend_bbox_to_anchor into a separate function. This will make the
    code cleaner and easier to test.

    pyretailscience/standard_graphs.py [104-105]

    -if move_legend_outside:
    -    legend_bbox_to_anchor = (1.05, 1)
    +legend_bbox_to_anchor = get_legend_position(move_legend_outside)
     
    +def get_legend_position(move_legend_outside):
    +    return (1.05, 1) if move_legend_outside else None
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Refactoring the legend positioning logic into a separate function improves code readability and maintainability. It makes the code cleaner and easier to test, which is beneficial for long-term maintenance.

    7
    Enhancement
    Allow legend_bbox_to_anchor to be passed as an optional parameter

    To enhance the flexibility of the time_plot function, consider allowing
    legend_bbox_to_anchor to be passed as an optional parameter. This would enable users
    to specify custom positions for the legend based on their specific requirements.

    pyretailscience/standard_graphs.py [103-105]

    -legend_bbox_to_anchor = None
    -if move_legend_outside:
    -    legend_bbox_to_anchor = (1.05, 1)
    +def time_plot(..., legend_bbox_to_anchor=None, ...):
    +    if move_legend_outside and legend_bbox_to_anchor is None:
    +        legend_bbox_to_anchor = (1.05, 1)
     
    Suggestion importance[1-10]: 6

    Why: Allowing legend_bbox_to_anchor to be passed as an optional parameter enhances the flexibility of the time_plot function. However, it adds complexity to the function signature, which may not be necessary for all use cases.

    6
    Change the default value of move_legend_outside to False to allow explicit enabling

    Consider adding a default value for move_legend_outside in the function signature to
    maintain consistency with other optional parameters and to ensure that it can be
    overridden when necessary.

    pyretailscience/standard_graphs.py [31]

    -move_legend_outside: bool = True,
    +move_legend_outside: bool = False,
     
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Changing the default value of move_legend_outside to False is a minor enhancement that could make the function's behavior more explicit. However, the current default of True is also reasonable and does not introduce any issues.

    5

    Copy link

    codecov bot commented Jul 20, 2024

    Codecov Report

    Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

    Files Coverage Δ
    pyretailscience/standard_graphs.py 42.30% <0.00%> (ø)

    Copy link

    @coderabbitai coderabbitai bot left a comment

    Choose a reason for hiding this comment

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

    Actionable comments posted: 0

    Outside diff range, codebase verification and nitpick comments (1)
    docs/analysis_modules.md (1)

    66-94: The time_plot function is not found in the codebase.

    The sample code snippet in docs/analysis_modules.md references a time_plot function that does not exist in the pyretailscience.standard_graphs module or any other part of the codebase. This makes the provided code snippet incorrect.

    • The time_plot function is neither defined in pyretailscience/standard_graphs.py nor imported from another module.
    • Ensure that the correct function name is used or provide the implementation of the time_plot function if it is missing.
    Analysis chain

    Verify the correctness of the sample code snippet.

    Ensure that the sample code snippet for creating a timeline plot is correct and functional.

    Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Verify the correctness of the sample code snippet for creating a timeline plot.
    
    # Test: Check for syntax errors in the sample code snippet.
    echo 'import numpy as np
    import pandas as pd
    from pyretailscience.standard_graphs import time_plot
    
    rng = np.random.default_rng(42)
    df = pd.DataFrame(
        {
            "transaction_datetime": pd.concat([pd.Series(pd.date_range(start="2022-01-01", periods=200, freq="D"))] * 3),
            "total_price": np.concatenate([rng.integers(1, 1000, size=200) * multiplier for multiplier in range(1, 4)]),
            "group": ["Group A"] * 200 + ["Group B"] * 200 + ["Group C"] * 200,
        },
    )
    
    time_plot(
        df,
        period="M",
        group_col="group",
        value_col="total_price",
        agg_func="sum",
        title="Monthly Sales by Customer Group",
        y_label="Sales",
        legend_title="Customer Group",
        source_text="Source: PyRetailScience - Sales FY2024",
        move_legend_outside=True,
    )' | python3 -m py_compile -
    if [ $? -ne 0 ]; then
      echo "Syntax errors found in the sample code snippet."
      exit 1
    fi
    echo "No syntax errors found in the sample code snippet."
    

    Length of output: 1014


    Script:

    #!/bin/bash
    # Check if the time_plot function exists in the pyretailscience.standard_graphs module
    ast-grep --lang python --pattern $'def time_plot($_, $_, $_, $_, $_, $_, $_, $_, $_, $_):' 
    
    # Check if numpy is imported in the codebase
    rg 'import numpy as np'
    
    # Check if pandas is imported in the codebase
    rg 'import pandas as pd'
    

    Length of output: 1512


    Script:

    #!/bin/bash
    # List all function definitions in the pyretailscience/standard_graphs.py file
    ast-grep --lang python --pattern 'def $_($_):' pyretailscience/standard_graphs.py
    
    # Search for any imports within the pyretailscience/standard_graphs.py file
    rg '^import ' pyretailscience/standard_graphs.py
    rg '^from ' pyretailscience/standard_graphs.py
    

    Length of output: 513

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 8992a63 and 04c9203.

    Files ignored due to path filters (1)
    • docs/assets/images/analysis_modules/time_plot.svg is excluded by !**/*.svg
    Files selected for processing (3)
    • .markdownlint.json (1 hunks)
    • docs/analysis_modules.md (2 hunks)
    • pyretailscience/standard_graphs.py (4 hunks)
    Files skipped from review due to trivial changes (1)
    • .markdownlint.json
    Additional comments not posted (6)
    docs/analysis_modules.md (2)

    46-63: Well-documented timeline plot section.

    The new section on "Timeline Plot" is clear and comprehensive. It effectively explains the concept, use cases, and benefits of timeline plots.


    14-14: Verify the updated image path.

    Ensure that the new relative path for the waterfall plot image is correct and the image is displayed properly.

    Verification successful

    Verified the updated image path.

    The image file "waterfall.svg" exists at the specified path "docs/assets/images/analysis_modules/waterfall.svg", confirming the correctness of the updated image path.

    Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Verify the updated image path for the waterfall plot.
    
    # Test: Check if the image file exists at the new relative path.
    if [ ! -f "docs/assets/images/analysis_modules/waterfall.svg" ]; then
      echo "Image file not found at the new relative path."
      exit 1
    fi
    echo "Image file found at the new relative path."
    

    Length of output: 161

    pyretailscience/standard_graphs.py (4)

    31-31: New parameter move_legend_outside added.

    The new parameter move_legend_outside provides flexibility in legend positioning. Ensure that this parameter is used correctly in the function.


    36-45: Well-documented use cases for time_plot.

    The expanded documentation provides clear and detailed use cases for the time_plot function, enhancing user understanding.


    320-329: Well-documented use cases for waterfall_plot.

    The expanded documentation provides clear and detailed use cases for the waterfall_plot function, enhancing user understanding.


    61-61: Ensure proper handling of the new parameter.

    Verify that the move_legend_outside parameter is handled correctly within the function.

    Verification successful

    The move_legend_outside parameter is handled correctly within the time_plot function.

    The parameter is defined, documented, and used in a conditional statement within the function body.

    • Definition: move_legend_outside: bool = True,
    • Documentation: move_legend_outside (bool, optional): Whether to move the legend outside the plot. Defaults to True.
    • Usage: if move_legend_outside:
    Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Verify the handling of the `move_legend_outside` parameter in the `time_plot` function.
    
    # Test: Search for the usage of the `move_legend_outside` parameter within the function.
    rg --type python -A 10 $'def time_plot' | rg 'move_legend_outside'
    

    Length of output: 96


    Script:

    #!/bin/bash
    # Description: Verify the handling of the `move_legend_outside` parameter in the `time_plot` function.
    
    # Test: Search for the usage of the `move_legend_outside` parameter within the function.
    rg 'def time_plot' -t py -A 20 | rg 'move_legend_outside'
    

    Length of output: 130


    Script:

    #!/bin/bash
    # Description: Verify the handling of the `move_legend_outside` parameter in the `time_plot` function.
    
    # Test: Search for the usage of the `move_legend_outside` parameter within the function.
    rg 'def time_plot' -t py -A 50 | rg 'move_legend_outside'
    

    Length of output: 274


    Script:

    #!/bin/bash
    # Description: Verify the handling of the `move_legend_outside` parameter in the `time_plot` function.
    
    # Test: Search for the usage of the `move_legend_outside` parameter within the function.
    rg 'def time_plot' -t py -A 100 | rg 'move_legend_outside'
    

    Length of output: 342

    @murray-ds murray-ds force-pushed the timeplot_analysis_module_docs branch from 04c9203 to c81e719 Compare July 20, 2024 17:52
    Copy link

    @coderabbitai coderabbitai bot left a comment

    Choose a reason for hiding this comment

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

    Actionable comments posted: 0

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 04c9203 and c81e719.

    Files ignored due to path filters (2)
    • docs/assets/images/analysis_modules/time_plot.svg is excluded by !**/*.svg
    • docs/assets/images/analysis_modules/waterfall.svg is excluded by !**/*.svg
    Files selected for processing (3)
    • .markdownlint.json (1 hunks)
    • docs/analysis_modules.md (2 hunks)
    • pyretailscience/standard_graphs.py (4 hunks)
    Files skipped from review due to trivial changes (1)
    • .markdownlint.json
    Files skipped from review as they are similar to previous changes (2)
    • docs/analysis_modules.md
    • pyretailscience/standard_graphs.py

    @mvanwyk mvanwyk merged commit 9290b86 into main Jul 20, 2024
    2 checks passed
    @mvanwyk mvanwyk deleted the timeplot_analysis_module_docs branch July 20, 2024 17:55
    murray-ds pushed a commit that referenced this pull request Feb 2, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant