Skip to content

fix: added conditions to ensure group filter actually filters index plot output #296

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

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

Conversation

mayurkmmt
Copy link
Collaborator

@mayurkmmt mayurkmmt commented Jun 11, 2025

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for group filtering in index plot generation by adding assertions to verify correct group inclusion and data presence.

Copy link

coderabbitai bot commented Jun 11, 2025

Walkthrough

The test for generating an index plot with group filtering was updated to use different column values and now includes assertions that explicitly verify the plot only contains the specified groups after filtering. No changes were made to any public or exported entities.

Changes

File(s) Change Summary
tests/plots/test_index.py Modified the test to use different filter values and added assertions for correct group filtering.

Sequence Diagram(s)

sequenceDiagram
    participant Test as test_generates_index_plot_with_group_filter
    participant PlotFunc as Plot Function
    Test->>PlotFunc: Call with index_col="region", value_to_index="North", include_only_groups=["A", "B"]
    PlotFunc-->>Test: Return plot object
    Test->>Test: Extract y-axis tick labels from plot
    Test->>Test: Assert tick labels ⊆ {"A", "B"} and at least one group present
Loading

Possibly related PRs

Poem

In the land of plots, where data blooms bright,
Rabbits test filters by day and by night.
With regions and groups, they hop through the code,
Ensuring the right labels appear on the road.
A tick here, a check there—
Now group filtering works with care!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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: 1

🔭 Outside diff range comments (1)
tests/plots/test_index.py (1)

266-273: 💡 Verification agent

🧩 Analysis chain

Baseline region missing for one of the filtered groups – test may silently pass with incomplete coverage

index_col is now "region" and value_to_index is "North", but in the test_data fixture only the rows for category "A" have region == "North".
Category "B" never contains the baseline region, so its index will be NaN and most likely gets dropped inside plot().
The assertion that follows merely checks that some groups were plotted (subset check), therefore the test can still succeed even if category "B" is absent – i.e. the group filter is not really exercised for "B".

Consider extending/overriding the fixture inside this test so every filtered group has at least one "North" row, or switch back to an index_col that is present for all groups.
Example quick fix (override inside the test):

df = test_data.copy()
df.loc[df["category"] == "B", "region"] = "North"   # ensure baseline present

🏁 Script executed:

#!/bin/bash
set -e
echo "Searching for definition of 'test_data' fixture..."
rg "@pytest.fixture" -A 3 -n --color=never | grep -C 3 "test_data"
echo "---"
echo "Searching all references to 'test_data'..."
rg "test_data" -n --color=never

Length of output: 6966


🏁 Script executed:

#!/bin/bash
sed -n '180,260p' tests/plots/test_index.py

Length of output: 2601


🏁 Script executed:

#!/bin/bash
set -e
sed -n '260,340p' tests/plots/test_index.py

Length of output: 3043


Ensure baseline region for all filtered groups in the group‐filter test

The current fixture assigns "North" only to category "A", so when you filter to ["A","B"] with value_to_index="North", category "B" lacks a baseline and will be dropped—yet the test only asserts a non‐empty subset, masking this gap.

Locations needing adjustment:

  • tests/plots/test_index.py: TestIndexPlot.test_generates_index_plot_with_group_filter (around lines 266–273)

Suggested change:

     def test_generates_index_plot_with_group_filter(self, test_data):
         """Test that the function generates an index plot with a group filter applied."""
-        df = test_data
+        df = test_data.copy()
+        # ensure baseline region 'North' exists for category 'B'
+        df.loc[df["category"] == "B", "region"] = "North"

         result_ax = plot(
             df,
             value_col="sales",
             group_col="category",
             index_col="region",
             value_to_index="North",
             include_only_groups=["A", "B"],
         )

This guarantees both "A" and "B" have a "North" index to validate the group filter properly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbd9960 and da9239a.

📒 Files selected for processing (1)
  • tests/plots/test_index.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Pre-Commit

Comment on lines +277 to +288
# Verify that only the filtered groups appear in the plot
y_labels = [label.get_text() for label in result_ax.get_yticklabels()]
plotted_groups = set(y_labels)
expected_groups = {"A", "B"}

assert plotted_groups.issubset(expected_groups), (
f"Found groups {plotted_groups - expected_groups} that should have been filtered out. "
f"Expected only groups from {expected_groups}."
)

assert len(plotted_groups) > 0, "No groups were plotted - filtering may have removed all data."

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Assertion too weak – should require exact group match

At the moment you only verify that the plotted groups are a subset of { "A", "B" }, which would still pass if only "A" appears.
Since the purpose is to guarantee the filter shows only the requested groups and that both groups survived the pipeline, assert equality:

-# Verify that only the filtered groups appear in the plot
-y_labels = [label.get_text() for label in result_ax.get_yticklabels()]
-plotted_groups = set(y_labels)
-expected_groups = {"A", "B"}
-
-assert plotted_groups.issubset(expected_groups), (
-    f"Found groups {plotted_groups - expected_groups} that should have been filtered out. "
-    f"Expected only groups from {expected_groups}."
-)
-
-assert len(plotted_groups) > 0, "No groups were plotted - filtering may have removed all data."
+# Verify that exactly the requested groups appear in the plot
+y_labels = [label.get_text() for label in result_ax.get_yticklabels()]
+plotted_groups = set(y_labels)
+expected_groups = {"A", "B"}
+
+assert plotted_groups == expected_groups, (
+    f"Expected groups {expected_groups}, got {plotted_groups}."
+)

This both guarantees no extra groups slip through and that none of the requested ones were dropped.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Verify that only the filtered groups appear in the plot
y_labels = [label.get_text() for label in result_ax.get_yticklabels()]
plotted_groups = set(y_labels)
expected_groups = {"A", "B"}
assert plotted_groups.issubset(expected_groups), (
f"Found groups {plotted_groups - expected_groups} that should have been filtered out. "
f"Expected only groups from {expected_groups}."
)
assert len(plotted_groups) > 0, "No groups were plotted - filtering may have removed all data."
# Verify that exactly the requested groups appear in the plot
y_labels = [label.get_text() for label in result_ax.get_yticklabels()]
plotted_groups = set(y_labels)
expected_groups = {"A", "B"}
assert plotted_groups == expected_groups, (
f"Expected groups {expected_groups}, got {plotted_groups}."
)
🤖 Prompt for AI Agents
In tests/plots/test_index.py around lines 277 to 288, the assertion currently
checks if the plotted groups are a subset of {"A", "B"}, which allows cases
where only one group appears. Change the assertion to require exact equality
between plotted_groups and expected_groups to ensure that both "A" and "B" are
present and no extra groups appear. Replace the issubset check with an equality
check and update the assertion message accordingly.

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