-
Notifications
You must be signed in to change notification settings - Fork 49
Upgrade pomegranate
dependency to Python 3.13
#736
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e91ed28
def
R-Palazzo fbdf5f6
tests
R-Palazzo 4c00cf7
update workflows
R-Palazzo f829f7f
use torch.tensor
R-Palazzo 8f133a7
update pomegranate version
R-Palazzo b68060b
fix 3.8 workflows + minimum tests
R-Palazzo cf7568e
fix minimum version 2 (python 3.10)
R-Palazzo af2257b
upgrade to 1.1.2
R-Palazzo 208c92a
add import error handling
R-Palazzo 9d9dc59
update pyproject and workflows
R-Palazzo 5568431
update pyproject
R-Palazzo 568b722
use replace()
R-Palazzo 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
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 |
---|---|---|
@@ -1,43 +1,97 @@ | ||
import sys | ||
from unittest.mock import Mock | ||
import re | ||
from unittest.mock import Mock, patch | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
||
from sdmetrics.single_table import BNLikelihood, BNLogLikelihood | ||
|
||
|
||
@pytest.fixture | ||
def bad_pomegranate(): | ||
old_pomegranate = getattr(sys.modules, 'pomegranate', None) | ||
sys.modules['pomegranate'] = pytest | ||
yield | ||
if old_pomegranate is not None: | ||
sys.modules['pomegranate'] = old_pomegranate | ||
else: | ||
del sys.modules['pomegranate'] | ||
def real_data(): | ||
return pd.DataFrame({ | ||
'a': ['a', 'b', 'a', 'b', 'a', 'b'], | ||
'b': ['c', 'd', 'c', 'd', 'c', 'd'], | ||
'c': [True, False, True, False, True, False], | ||
'd': [1, 2, 3, 4, 5, 6], | ||
'e': [10, 2, 3, 4, 5, 6], | ||
}) | ||
|
||
|
||
@pytest.fixture | ||
def synthetic_data(): | ||
return pd.DataFrame({ | ||
'a': ['a', 'b', 'b', 'b', 'a', 'b'], | ||
'b': ['d', 'd', 'c', 'd', 'c', 'd'], | ||
'c': [False, False, True, False, True, False], | ||
'd': [4, 2, 3, 4, 5, 6], | ||
'e': [12, 2, 3, 4, 5, 6], | ||
}) | ||
|
||
|
||
@pytest.fixture | ||
def metadata(): | ||
return { | ||
'columns': { | ||
'a': {'sdtype': 'categorical'}, | ||
'b': {'sdtype': 'categorical'}, | ||
'c': {'sdtype': 'boolean'}, | ||
'd': {'sdtype': 'categorical'}, | ||
'e': {'sdtype': 'numerical'}, | ||
} | ||
} | ||
|
||
|
||
class TestBNLikelihood: | ||
def test_compute(self, bad_pomegranate): | ||
"""Test that an ``ImportError`` is raised.""" | ||
@patch.dict('sys.modules', {'pomegranate.bayesian_network': None}) | ||
def test_compute_error(self): | ||
"""Test that an `ImportError` is raised.""" | ||
# Setup | ||
metric = BNLikelihood() | ||
|
||
# Act and Assert | ||
expected_message = r'Please install pomegranate with `pip install sdmetrics\[pomegranate\]`\. Python 3\.13 is not supported\.' # noqa: E501 | ||
# Run and Assert | ||
expected_message = re.escape( | ||
'Please install pomegranate with `pip install sdmetrics[pomegranate]`.' | ||
) | ||
with pytest.raises(ImportError, match=expected_message): | ||
metric.compute(Mock(), Mock()) | ||
|
||
def test_compute(self, real_data, synthetic_data, metadata): | ||
"""Test the ``compute``method.""" | ||
# Setup | ||
np.random.seed(42) | ||
metric = BNLikelihood() | ||
|
||
# Run | ||
result = metric.compute(real_data, synthetic_data, metadata) | ||
|
||
# Assert | ||
assert np.isclose(result, 0.1111111044883728, atol=1e-5) | ||
|
||
|
||
class TestBNLogLikelihood: | ||
def test_compute(self, bad_pomegranate): | ||
"""Test that an ``ImportError`` is raised.""" | ||
@patch.dict('sys.modules', {'pomegranate.bayesian_network': None}) | ||
def test_compute_error(self): | ||
"""Test that an `ImportError` is raised.""" | ||
# Setup | ||
metric = BNLogLikelihood() | ||
|
||
# Act and Assert | ||
expected_message = expected_message = ( | ||
r'Please install pomegranate with `pip install sdmetrics\[pomegranate\]`\. Python 3\.13 is not supported\.' # noqa: E501 | ||
# Run and Assert | ||
expected_message = re.escape( | ||
'Please install pomegranate with `pip install sdmetrics[pomegranate]`.' | ||
) | ||
with pytest.raises(ImportError, match=expected_message): | ||
metric.compute(Mock(), Mock()) | ||
|
||
def test_compute(self, real_data, synthetic_data, metadata): | ||
"""Test the ``compute``method.""" | ||
# Setup | ||
np.random.seed(42) | ||
metric = BNLogLikelihood() | ||
|
||
# Run | ||
result = metric.compute(real_data, synthetic_data, metadata) | ||
|
||
# Assert | ||
assert np.isclose(result, -7.334733486175537, atol=1e-5) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tests ensure the metric computation remains consistent while upgrading pomegranate.