-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix/tcolor preserve metadata #20046
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
Closed
aviralgarg05
wants to merge
2
commits into
root-project:master
from
aviralgarg05:fix/tcolor-preserve-metadata
Closed
Fix/tcolor preserve metadata #20046
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "b8ef0e09", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import ROOT" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ac871508", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "ROOT.TColor.DefinedColors(1)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "4800d2c7", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "c = ROOT.TCanvas(\"c\", \"Basic ROOT Plot\", 800, 600)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "f3900d8a", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "h = ROOT.TH1F(\"h\", \"Example Histogram;X axis;Entries\", 100, 0, 10)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "d83cc9da", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "for _ in range(10000):\n", | ||
| " h.Fill(ROOT.gRandom.Gaus(5, 1))" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "1df7d032", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "h.Draw()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "3743fddc", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "c.Draw()" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Test script to verify that TColor.DefinedColors works correctly in Jupyter-like environments. | ||
| This test verifies the fix for issue #20018. | ||
| """ | ||
| import sys | ||
|
|
||
|
|
||
| def test_tcolor_metadata_preservation(): | ||
| """ | ||
| Test that TColor.__init__ preserves metadata after pythonization. | ||
| This ensures that introspection-heavy environments like Jupyter can | ||
| properly inspect the method. | ||
| """ | ||
| import ROOT | ||
|
|
||
| # Check that __init__ has the expected attributes from functools.wraps | ||
| assert hasattr(ROOT.TColor.__init__, '__wrapped__'), \ | ||
| "TColor.__init__ should have __wrapped__ attribute from functools.wraps" | ||
|
|
||
| # Check that __name__ is preserved | ||
| assert hasattr(ROOT.TColor.__init__, '__name__'), \ | ||
| "TColor.__init__ should have __name__ attribute" | ||
|
|
||
| # Check that __doc__ is preserved | ||
| assert hasattr(ROOT.TColor.__init__, '__doc__'), \ | ||
| "TColor.__init__ should have __doc__ attribute" | ||
|
|
||
| print("Metadata preservation test: PASSED") | ||
| return True | ||
|
|
||
| def test_tcolor_definedcolors(): | ||
| """ | ||
| Test the original issue: TColor.DefinedColors(1) should work without errors. | ||
| """ | ||
| import ROOT | ||
|
|
||
| try: | ||
| # This was the problematic call in Jupyter notebooks | ||
| result = ROOT.TColor.DefinedColors(1) | ||
| print(f"TColor.DefinedColors(1) returned: {result}") | ||
| print("DefinedColors test: PASSED") | ||
| return True | ||
| except Exception as e: | ||
| print(f"TColor.DefinedColors(1) failed with error: {e}") | ||
| print("DefinedColors test: FAILED") | ||
| return False | ||
|
|
||
| def test_tcolor_full_workflow(): | ||
| """ | ||
| Test the full workflow from the original issue report. | ||
| """ | ||
| import ROOT | ||
|
|
||
| try: | ||
| # Create a canvas | ||
| ROOT.TColor.DefinedColors(1) | ||
| c = ROOT.TCanvas("c", "Basic ROOT Plot", 800, 600) | ||
|
|
||
| # Create a histogram with 100 bins from 0 to 10 | ||
| h = ROOT.TH1F("h", "Example Histogram;X axis;Entries", 100, 0, 10) | ||
|
|
||
| # Fill histogram with random Gaussian numbers | ||
| for _ in range(10000): | ||
| h.Fill(ROOT.gRandom.Gaus(5, 1)) | ||
|
|
||
| # Draw the histogram | ||
| h.Draw() | ||
|
|
||
| # Draw canvas | ||
| c.Draw() | ||
|
|
||
| print("Full workflow test: PASSED") | ||
| return True | ||
| except Exception as e: | ||
| print(f"Full workflow test failed with error: {e}") | ||
| print("Full workflow test: FAILED") | ||
| return False | ||
|
|
||
| def main(): | ||
| """ | ||
| Run all tests and return exit code. | ||
| """ | ||
| print("=" * 60) | ||
| print("Testing TColor metadata preservation fix for issue #20018") | ||
| print("=" * 60) | ||
|
|
||
| tests = [ | ||
| test_tcolor_metadata_preservation, | ||
| test_tcolor_definedcolors, | ||
| test_tcolor_full_workflow | ||
| ] | ||
|
|
||
| results = [] | ||
| for test in tests: | ||
| print(f"\nRunning {test.__name__}...") | ||
| try: | ||
| result = test() | ||
| results.append(result) | ||
| except Exception as e: | ||
| print(f"Test {test.__name__} raised exception: {e}") | ||
| results.append(False) | ||
|
|
||
| print("\n" + "=" * 60) | ||
| print(f"Test Results: {sum(results)}/{len(results)} passed") | ||
| print("=" * 60) | ||
|
|
||
| return 0 if all(results) else 1 | ||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
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.
Uh oh!
There was an error while loading. Please reload this page.