Skip to content

Conversation

gmolledaj
Copy link
Contributor

Issue NONE
  • Adds a language-independent Cochran indicator (green/red square) below χ² and p.
  • Exposes an internal flag (_cochran_ok) for testing.
  • Adds tests for both cases: condition satisfied and violated.
  • No changes to existing color scheme or behavior of Sieve cells.
Description of changes

This pull request introduces the following changes:

Cochran’s rule indicator in Sieve widget

Adds a small green/red square below the χ² and p-value labels.

The indicator turns green when Cochran’s rule is satisfied and red otherwise.

A new internal attribute (_cochran_ok) stores the evaluation result.

Unit tests

Added tests to ensure the indicator behaves correctly:

test_cochran_indicator_passes checks that the indicator is green when conditions are satisfied.

test_cochran_indicator_fails checks that the indicator is red when conditions are violated.

These changes improve the statistical robustness of the Sieve visualization and provide users with a quick visual check of Cochran’s rule.

Includes
  • Code changes
  • Tests
  • Documentation

Implemented a Cochran condition check based on expected frequencies in the Sieve Diagram widget. A small green or red square is displayed next to the "Cochran:" label to indicate whether the rule is satisfied. 
This provides a quick, language-independent visual cue without altering the existing color scheme of the diagram.
…gram

2nd change for add tests
Implemented a Cochran condition check based on expected frequencies in the Sieve Diagram widget. A small green or red square is displayed next to the "Cochran:" label to indicate whether the rule is satisfied. 
This provides a quick, language-independent visual cue without altering the existing color scheme of the diagram.
2nd change: add Cochran rule check with visual indicator to Sieve Dia…
Introduced a new unit test that checks the Cochran’s rule indicator in the Sieve widget.
The test uses a balanced 3x3 contingency table, where all expected frequencies are greater than 5, ensuring that the Cochran condition is satisfied. This verifies that the widget correctly sets the internal flag and displays the green indicator.
Add test for Cochran indicator when condition is satisfied
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.79%. Comparing base (86ae451) to head (7748fc4).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7150      +/-   ##
==========================================
+ Coverage   88.78%   88.79%   +0.01%     
==========================================
  Files         334      335       +1     
  Lines       73700    73876     +176     
==========================================
+ Hits        65434    65600     +166     
- Misses       8266     8276      +10     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This commit updates and refines the Cochran indicator logic added in the previous patch:
Groups the label and square into a single QGraphicsItemGroup for consistent positioning.
Ensures old indicators are properly removed before drawing new ones.
Uses cosmetic pens to avoid scaling artifacts on HiDPI displays.
Adds defensive checks to keep the indicator inside the scene bounds.
Improves robustness so tests and different rendering backends behave consistently.
This is a follow-up to the earlier patch that introduced the Cochran rule indicator, addressing review feedback and making the feature more reliable.
Refine Cochran indicator added in previous patch
Adjusted bottom margin so the Cochran indicator is rendered correctly and does not get clipped when resizing the window.
…in-Sieve-widget

Fix Cochran indicator positioning in Sieve widget
Cleaned up trailing spaces to improve code style consistency and pass linting checks.
Remove trailing whitespace in test_owsieve.py
- Replaced redundant list comprehensions with simpler list() calls or slicing.
- Switched from dict() constructor to dictionary literal for readability.
- Renamed imported 'filter' to avoid redefining the built-in name.

These are code quality improvements only, with no functional changes.
Refactor comprehensions, dict creation, and rename 'filter' import
- Added new tests to cover Cochran’s rule indicator (pass and fail cases).
- Extended test_input_features to verify attribute resolution.
- Added test for update_selection to ensure selected and annotated outputs are produced.
Update and extend Sieve widget tests
@gmolledaj
Copy link
Contributor Author

gmolledaj commented Aug 23, 2025

Hi, just to clarify the current state of this PR:

When I opened it, I started getting CI errors from other parts of the codebase not related to my changes. While I tried to fix them, it created even more unrelated warnings and errors, although I believe the core changes I introduced are correct (example: refactor comprehensions, dict creation and filter import).

Regarding translations: there is only one new string, currently "Cochran:". This should more precisely be "Cochran’s rules:", and ideally it should go through the i18n system.

If you prefer, I can close this PR and reopen a clean one with only the original intended changes, without the extra attempts to fix unrelated issues.

Thanks for the review and guidance!

@janezd
Copy link
Contributor

janezd commented Aug 23, 2025

@gmolledaj, thanks for your patience.

Some tests crash at random; this is annoying but impossible to debug and fix. We would, hopefully, one day. For now, ignore them.

As for Slovenian translations, it obviously has to be done by somebody else (probably: me) after @thocevar or I review your PR. (We were the obvious choice so we volunteered, but we're both too busy right now.)

@gmolledaj
Copy link
Contributor Author

@gmolledaj, thanks for your patience.

Some tests crash at random; this is annoying but impossible to debug and fix. We would, hopefully, one day. For now, ignore them.

As for Slovenian translations, it obviously has to be done by somebody else (probably: me) after @thocevar or I review your PR. (We were the obvious choice so we volunteered, but we're both too busy right now.)

Thanks for the update! I completely understand that you’re busy right now.
In the meantime, I’m attaching a small dataset I prepared — it produces a case where Cochran’s rule fails (indicator turns red). It might be useful for testing or validation later.
cochran_fail_example.csv

@janezd
Copy link
Contributor

janezd commented Aug 29, 2025

Warning the user about inadequate data size is a good idea, but the meaning of the red/green square is not self evident. I understand your wish to make it language-independent --- but I don't think it works; there has to be some text to explain it.

@thocevar proposed to make this a warning in the status line, e.g.

    class Warning(OWWidget.Warning):
        inadequate_data_size = Msg("Small data size.\n{}")

and the you can trigger it with self.Warning.inadequate_data_size(reason), where reason is a string that explains which criterion isn't met. It will be shown on mouse hover. Don't forget to clear the warning.

Doing it this way is more in line with other Orange widgets, and it also doesn't take additional space. It also simplifies the code because you don't have to paint the square, and you don't need the extra attribute _cochran_ok.

- Added _cochran_ok() method to evaluate Cochran’s rule
- Show Information message when the rule is met
- Show Warning message when the rule is not met
Cochran with message Warning and Information
- Added tests with balanced and unbalanced contingency tables
- Verify that Information is shown when the rule is met
- Verify that Warning is shown when the rule is not met
Add tests for Cochran’s rule messages in Sieve Diagram
@janezd janezd self-assigned this Sep 12, 2025
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.

3 participants