From 0602305c5eba6c4c51cd2819df61603fcb511da3 Mon Sep 17 00:00:00 2001 From: gsheni Date: Wed, 1 May 2024 13:03:56 -0400 Subject: [PATCH] lint doc strings --- copulas/multivariate/gaussian.py | 4 +--- pyproject.toml | 20 ++++++++++--------- tests/end-to-end/bivariate/test_base.py | 1 - tests/end-to-end/multivariate/test_base.py | 1 - .../end-to-end/multivariate/test_gaussian.py | 1 - tests/end-to-end/test___init__.py | 1 - tests/end-to-end/univariate/test_beta.py | 3 +-- tests/end-to-end/univariate/test_gamma.py | 3 +-- tests/end-to-end/univariate/test_gaussian.py | 3 +-- .../univariate/test_gaussian_kde.py | 3 +-- tests/end-to-end/univariate/test_student_t.py | 3 +-- .../univariate/test_truncated_gaussian.py | 3 +-- tests/large_scale_evaluation.py | 3 +-- tests/numerical/cdf/test_cdf.py | 1 - tests/numerical/fit/test_fit.py | 1 - tests/numerical/pdf/test_pdf.py | 1 - tests/unit/bivariate/test___init__.py | 3 +-- tests/unit/bivariate/test_base.py | 2 +- tests/unit/bivariate/test_clayton.py | 2 +- tests/unit/bivariate/test_frank.py | 2 +- tests/unit/bivariate/test_gumbel.py | 2 +- tests/unit/bivariate/test_independence.py | 1 - tests/unit/multivariate/test_base.py | 1 - tests/unit/multivariate/test_gaussian.py | 5 +---- tests/unit/multivariate/test_tree.py | 2 +- tests/unit/multivariate/test_vine.py | 6 ++---- tests/unit/optimize/test___init__.py | 1 - tests/unit/test___init__.py | 5 ++--- tests/unit/univariate/test_base.py | 2 +- tests/unit/univariate/test_beta.py | 3 +-- tests/unit/univariate/test_gamma.py | 3 +-- tests/unit/univariate/test_gaussian.py | 3 +-- tests/unit/univariate/test_gaussian_kde.py | 3 +-- tests/unit/univariate/test_log_laplace.py | 3 +-- tests/unit/univariate/test_selection.py | 3 +-- tests/unit/univariate/test_student_t.py | 3 +-- .../univariate/test_truncated_gaussian.py | 3 +-- tests/unit/univariate/test_uniform.py | 3 +-- 38 files changed, 40 insertions(+), 73 deletions(-) diff --git a/copulas/multivariate/gaussian.py b/copulas/multivariate/gaussian.py index 6a2f5f8e..2c0437be 100644 --- a/copulas/multivariate/gaussian.py +++ b/copulas/multivariate/gaussian.py @@ -155,9 +155,7 @@ def probability_density(self, X): self.check_fit() transformed = self._transform_to_normal(X) - return stats.multivariate_normal.pdf( - transformed, cov=self.correlation, allow_singular=True - ) + return stats.multivariate_normal.pdf(transformed, cov=self.correlation, allow_singular=True) def cumulative_distribution(self, X): """Compute the cumulative distribution value for each point in X. diff --git a/pyproject.toml b/pyproject.toml index 9c5ebe6b..7c9cd8cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -171,11 +171,11 @@ filename = 'copulas/__init__.py' search = "__version__ = '{current_version}'" replace = "__version__ = '{new_version}'" - [tool.ruff] preview = true -line-length = 99 -src = ["copulas"] +line-length = 100 +indent-width = 4 +src = ["rdt"] target-version = "py312" exclude = [ "docs", @@ -201,19 +201,21 @@ ignore = [ "D417", # Missing argument descriptions in the docstring, this is a bug from pydocstyle: https://github.com/PyCQA/pydocstyle/issues/449 ] +[tool.ruff.format] +quote-style = "single" +indent-style = "space" +preview = true +docstring-code-format = true +docstring-code-line-length = "dynamic" + [tool.ruff.lint.pep8-naming] extend-ignore-names = ["X", "C", "X_padded", "Y", "Y_padded"] [tool.ruff.lint.isort] -known-first-party = ["copulas"] +known-first-party = ["rdt"] [tool.ruff.lint.per-file-ignores] "__init__.py" = ["F401", "E402", "F403", "F405", "E501", "I001"] -[tool.ruff.format] -quote-style = "single" -indent-style = "space" -preview = true - [tool.ruff.lint.pydocstyle] convention = "google" \ No newline at end of file diff --git a/tests/end-to-end/bivariate/test_base.py b/tests/end-to-end/bivariate/test_base.py index eb346eb1..c66e8d85 100644 --- a/tests/end-to-end/bivariate/test_base.py +++ b/tests/end-to-end/bivariate/test_base.py @@ -1,6 +1,5 @@ import numpy as np import pytest - from copulas.bivariate import Bivariate diff --git a/tests/end-to-end/multivariate/test_base.py b/tests/end-to-end/multivariate/test_base.py index 4e61be5f..8b53405f 100644 --- a/tests/end-to-end/multivariate/test_base.py +++ b/tests/end-to-end/multivariate/test_base.py @@ -1,6 +1,5 @@ import numpy as np import pytest - from copulas.datasets import sample_trivariate_xyz from copulas.multivariate import GaussianMultivariate, VineCopula diff --git a/tests/end-to-end/multivariate/test_gaussian.py b/tests/end-to-end/multivariate/test_gaussian.py index 7b294868..ea535561 100644 --- a/tests/end-to-end/multivariate/test_gaussian.py +++ b/tests/end-to-end/multivariate/test_gaussian.py @@ -5,7 +5,6 @@ import numpy as np import pandas as pd - from copulas.datasets import sample_trivariate_xyz from copulas.multivariate import GaussianMultivariate from copulas.univariate import BetaUnivariate, GaussianKDE, ParametricType, Univariate diff --git a/tests/end-to-end/test___init__.py b/tests/end-to-end/test___init__.py index 1eb568be..bc75bc2b 100644 --- a/tests/end-to-end/test___init__.py +++ b/tests/end-to-end/test___init__.py @@ -1,5 +1,4 @@ import numpy as np - from copulas import random_state diff --git a/tests/end-to-end/univariate/test_beta.py b/tests/end-to-end/univariate/test_beta.py index 1f453001..80554b95 100644 --- a/tests/end-to-end/univariate/test_beta.py +++ b/tests/end-to-end/univariate/test_beta.py @@ -3,9 +3,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import beta - from copulas.univariate import BetaUnivariate +from scipy.stats import beta class TestGaussian(TestCase): diff --git a/tests/end-to-end/univariate/test_gamma.py b/tests/end-to-end/univariate/test_gamma.py index 31c8f22f..58e49ca0 100644 --- a/tests/end-to-end/univariate/test_gamma.py +++ b/tests/end-to-end/univariate/test_gamma.py @@ -3,9 +3,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import gamma - from copulas.univariate import GammaUnivariate +from scipy.stats import gamma class TestGaussian(TestCase): diff --git a/tests/end-to-end/univariate/test_gaussian.py b/tests/end-to-end/univariate/test_gaussian.py index 6c160ddc..14984bd0 100644 --- a/tests/end-to-end/univariate/test_gaussian.py +++ b/tests/end-to-end/univariate/test_gaussian.py @@ -3,9 +3,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import norm - from copulas.univariate import GaussianUnivariate +from scipy.stats import norm class TestGaussian(TestCase): diff --git a/tests/end-to-end/univariate/test_gaussian_kde.py b/tests/end-to-end/univariate/test_gaussian_kde.py index f1c77f73..a210cdb8 100644 --- a/tests/end-to-end/univariate/test_gaussian_kde.py +++ b/tests/end-to-end/univariate/test_gaussian_kde.py @@ -3,11 +3,10 @@ from unittest import TestCase import numpy as np -from scipy.stats import ks_2samp, norm, randint - from copulas.datasets import sample_univariate_bimodal from copulas.multivariate import GaussianMultivariate from copulas.univariate.gaussian_kde import GaussianKDE +from scipy.stats import ks_2samp, norm, randint class TestGaussian(TestCase): diff --git a/tests/end-to-end/univariate/test_student_t.py b/tests/end-to-end/univariate/test_student_t.py index a1f5c6af..a145043e 100644 --- a/tests/end-to-end/univariate/test_student_t.py +++ b/tests/end-to-end/univariate/test_student_t.py @@ -3,9 +3,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import t - from copulas.univariate import StudentTUnivariate +from scipy.stats import t class TestStudentT(TestCase): diff --git a/tests/end-to-end/univariate/test_truncated_gaussian.py b/tests/end-to-end/univariate/test_truncated_gaussian.py index 707519c2..f894aaf1 100644 --- a/tests/end-to-end/univariate/test_truncated_gaussian.py +++ b/tests/end-to-end/univariate/test_truncated_gaussian.py @@ -3,9 +3,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import truncnorm - from copulas.univariate import TruncatedGaussian +from scipy.stats import truncnorm class TestGaussian(TestCase): diff --git a/tests/large_scale_evaluation.py b/tests/large_scale_evaluation.py index 0a5d6471..e52b5f42 100644 --- a/tests/large_scale_evaluation.py +++ b/tests/large_scale_evaluation.py @@ -43,11 +43,10 @@ import tabulate from botocore import UNSIGNED from botocore.client import Config -from scipy.stats import ks_2samp - from copulas import get_instance from copulas.multivariate import GaussianMultivariate, VineCopula from copulas.univariate import GaussianUnivariate +from scipy.stats import ks_2samp LOGGER = logging.getLogger(__name__) diff --git a/tests/numerical/cdf/test_cdf.py b/tests/numerical/cdf/test_cdf.py index 13956867..6b61f995 100644 --- a/tests/numerical/cdf/test_cdf.py +++ b/tests/numerical/cdf/test_cdf.py @@ -5,7 +5,6 @@ import numpy as np import pandas as pd import pytest - from copulas import get_instance BASE = os.path.dirname(__file__) diff --git a/tests/numerical/fit/test_fit.py b/tests/numerical/fit/test_fit.py index b4c67c2b..19293732 100644 --- a/tests/numerical/fit/test_fit.py +++ b/tests/numerical/fit/test_fit.py @@ -5,7 +5,6 @@ import numpy as np import pandas as pd import pytest - from copulas import get_instance BASE = os.path.dirname(__file__) diff --git a/tests/numerical/pdf/test_pdf.py b/tests/numerical/pdf/test_pdf.py index 00099399..34a08b58 100644 --- a/tests/numerical/pdf/test_pdf.py +++ b/tests/numerical/pdf/test_pdf.py @@ -5,7 +5,6 @@ import numpy as np import pandas as pd import pytest - from copulas import get_instance BASE = os.path.dirname(__file__) diff --git a/tests/unit/bivariate/test___init__.py b/tests/unit/bivariate/test___init__.py index 140d61e0..4c6fbfa8 100644 --- a/tests/unit/bivariate/test___init__.py +++ b/tests/unit/bivariate/test___init__.py @@ -1,8 +1,7 @@ import numpy as np -from scipy import stats - from copulas.bivariate import select_copula from copulas.bivariate.frank import Frank +from scipy import stats def test_select_copula_negative_tau(): diff --git a/tests/unit/bivariate/test_base.py b/tests/unit/bivariate/test_base.py index 6fb2a400..09b329f4 100644 --- a/tests/unit/bivariate/test_base.py +++ b/tests/unit/bivariate/test_base.py @@ -1,8 +1,8 @@ from unittest import TestCase, mock import numpy as np - from copulas.bivariate.base import Bivariate, CopulaTypes + from tests import compare_nested_dicts diff --git a/tests/unit/bivariate/test_clayton.py b/tests/unit/bivariate/test_clayton.py index d43d9542..dc6840cc 100644 --- a/tests/unit/bivariate/test_clayton.py +++ b/tests/unit/bivariate/test_clayton.py @@ -1,8 +1,8 @@ from unittest import TestCase import numpy as np - from copulas.bivariate.clayton import Clayton + from tests import copula_single_arg_not_one, copula_zero_if_arg_zero diff --git a/tests/unit/bivariate/test_frank.py b/tests/unit/bivariate/test_frank.py index b053511e..adc15007 100644 --- a/tests/unit/bivariate/test_frank.py +++ b/tests/unit/bivariate/test_frank.py @@ -2,8 +2,8 @@ from unittest.mock import patch import numpy as np - from copulas.bivariate.frank import Frank + from tests import compare_nested_iterables, copula_single_arg_not_one, copula_zero_if_arg_zero diff --git a/tests/unit/bivariate/test_gumbel.py b/tests/unit/bivariate/test_gumbel.py index e70f077a..f1a05357 100644 --- a/tests/unit/bivariate/test_gumbel.py +++ b/tests/unit/bivariate/test_gumbel.py @@ -2,8 +2,8 @@ from unittest.mock import patch import numpy as np - from copulas.bivariate.gumbel import Gumbel + from tests import compare_nested_iterables, copula_single_arg_not_one, copula_zero_if_arg_zero diff --git a/tests/unit/bivariate/test_independence.py b/tests/unit/bivariate/test_independence.py index 5d3a7009..e2927bae 100644 --- a/tests/unit/bivariate/test_independence.py +++ b/tests/unit/bivariate/test_independence.py @@ -1,7 +1,6 @@ from unittest import TestCase import numpy as np - from copulas.bivariate.independence import Independence diff --git a/tests/unit/multivariate/test_base.py b/tests/unit/multivariate/test_base.py index 00575ae7..7e5c9115 100644 --- a/tests/unit/multivariate/test_base.py +++ b/tests/unit/multivariate/test_base.py @@ -1,5 +1,4 @@ import numpy as np - from copulas.multivariate.base import Multivariate diff --git a/tests/unit/multivariate/test_gaussian.py b/tests/unit/multivariate/test_gaussian.py index c99f6eb8..c9dcc17a 100644 --- a/tests/unit/multivariate/test_gaussian.py +++ b/tests/unit/multivariate/test_gaussian.py @@ -3,7 +3,6 @@ import numpy as np import pandas as pd - from copulas import get_qualified_name from copulas.multivariate.gaussian import GaussianMultivariate from copulas.univariate import GaussianUnivariate @@ -309,9 +308,7 @@ def test_fit_distribution_selector(self): def test_fit_numpy_array(self): """Fit should work indistinctly with numpy arrays and pandas dataframes""" # Setup - copula = GaussianMultivariate( - distribution='copulas.univariate.gaussian.GaussianUnivariate' - ) + copula = GaussianMultivariate(distribution='copulas.univariate.gaussian.GaussianUnivariate') # Run copula.fit(self.data.to_numpy()) diff --git a/tests/unit/multivariate/test_tree.py b/tests/unit/multivariate/test_tree.py index 19ee0071..b0cf0704 100644 --- a/tests/unit/multivariate/test_tree.py +++ b/tests/unit/multivariate/test_tree.py @@ -5,11 +5,11 @@ import numpy as np import pandas as pd import pytest - from copulas import EPSILON from copulas.bivariate import CopulaTypes from copulas.multivariate.tree import Edge, Tree, TreeTypes, get_tree from copulas.univariate.gaussian_kde import GaussianKDE + from tests import compare_nested_dicts, compare_nested_iterables, compare_values_epsilon diff --git a/tests/unit/multivariate/test_vine.py b/tests/unit/multivariate/test_vine.py index ac3de726..e9e0d3b1 100644 --- a/tests/unit/multivariate/test_vine.py +++ b/tests/unit/multivariate/test_vine.py @@ -5,9 +5,9 @@ import numpy as np import pandas as pd import pytest - from copulas.multivariate.tree import TreeTypes from copulas.multivariate.vine import VineCopula + from tests import compare_nested_dicts, compare_nested_iterables @@ -203,9 +203,7 @@ def test_sample_random_state(self): X = pd.DataFrame([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) vine.fit(X) - expected_result = pd.DataFrame( - [[0.101933, 0.527734, 0.080266, 0.078328]], columns=range(4) - ) + expected_result = pd.DataFrame([[0.101933, 0.527734, 0.080266, 0.078328]], columns=range(4)) # Run result = vine.sample(1) diff --git a/tests/unit/optimize/test___init__.py b/tests/unit/optimize/test___init__.py index 47de5a6b..e39f265d 100644 --- a/tests/unit/optimize/test___init__.py +++ b/tests/unit/optimize/test___init__.py @@ -1,7 +1,6 @@ from unittest import TestCase import numpy as np - from copulas.optimize import bisect, chandrupatla diff --git a/tests/unit/test___init__.py b/tests/unit/test___init__.py index 2d9a4d68..4e91ec9d 100644 --- a/tests/unit/test___init__.py +++ b/tests/unit/test___init__.py @@ -2,12 +2,10 @@ from unittest import TestCase from unittest.mock import MagicMock, call, patch +import copulas import numpy as np import pandas as pd import pytest -from numpy.testing import assert_array_equal - -import copulas from copulas import ( _find_addons, check_valid_values, @@ -18,6 +16,7 @@ vectorize, ) from copulas.multivariate import GaussianMultivariate +from numpy.testing import assert_array_equal class TestVectorize(TestCase): diff --git a/tests/unit/univariate/test_base.py b/tests/unit/univariate/test_base.py index 26fb89c1..81fe7d34 100644 --- a/tests/unit/univariate/test_base.py +++ b/tests/unit/univariate/test_base.py @@ -1,7 +1,6 @@ from unittest.mock import patch import numpy as np - from copulas.univariate.base import BoundedType, ParametricType, Univariate from copulas.univariate.beta import BetaUnivariate from copulas.univariate.gamma import GammaUnivariate @@ -11,6 +10,7 @@ from copulas.univariate.student_t import StudentTUnivariate from copulas.univariate.truncated_gaussian import TruncatedGaussian from copulas.univariate.uniform import UniformUnivariate + from tests import compare_nested_iterables diff --git a/tests/unit/univariate/test_beta.py b/tests/unit/univariate/test_beta.py index 4bf30d3e..c33f34c6 100644 --- a/tests/unit/univariate/test_beta.py +++ b/tests/unit/univariate/test_beta.py @@ -2,9 +2,8 @@ from unittest.mock import patch import numpy as np -from scipy.stats import beta - from copulas.univariate import BetaUnivariate +from scipy.stats import beta class TestBetaUnivariate(TestCase): diff --git a/tests/unit/univariate/test_gamma.py b/tests/unit/univariate/test_gamma.py index df21ae2f..b522df89 100644 --- a/tests/unit/univariate/test_gamma.py +++ b/tests/unit/univariate/test_gamma.py @@ -1,9 +1,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import gamma - from copulas.univariate import GammaUnivariate +from scipy.stats import gamma class TestGammaUnivariate(TestCase): diff --git a/tests/unit/univariate/test_gaussian.py b/tests/unit/univariate/test_gaussian.py index 801fecd6..4413988b 100644 --- a/tests/unit/univariate/test_gaussian.py +++ b/tests/unit/univariate/test_gaussian.py @@ -1,9 +1,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import norm - from copulas.univariate.gaussian import GaussianUnivariate +from scipy.stats import norm class TestGaussianUnivariate(TestCase): diff --git a/tests/unit/univariate/test_gaussian_kde.py b/tests/unit/univariate/test_gaussian_kde.py index 92675006..437920ba 100644 --- a/tests/unit/univariate/test_gaussian_kde.py +++ b/tests/unit/univariate/test_gaussian_kde.py @@ -8,10 +8,9 @@ import numpy as np import pytest -from scipy.stats import gaussian_kde - from copulas.datasets import sample_univariate_bimodal from copulas.univariate.gaussian_kde import GaussianKDE +from scipy.stats import gaussian_kde class TestGaussianKDE(TestCase): diff --git a/tests/unit/univariate/test_log_laplace.py b/tests/unit/univariate/test_log_laplace.py index 80381159..c3aca984 100644 --- a/tests/unit/univariate/test_log_laplace.py +++ b/tests/unit/univariate/test_log_laplace.py @@ -1,9 +1,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import loglaplace - from copulas.univariate import LogLaplace +from scipy.stats import loglaplace class TestLogLaplaceUnivariate(TestCase): diff --git a/tests/unit/univariate/test_selection.py b/tests/unit/univariate/test_selection.py index 8aef778d..9841f321 100644 --- a/tests/unit/univariate/test_selection.py +++ b/tests/unit/univariate/test_selection.py @@ -1,10 +1,9 @@ from unittest.mock import Mock, patch import numpy as np -from scipy.stats import truncnorm - from copulas.univariate import BetaUnivariate, GaussianKDE, GaussianUnivariate, TruncatedGaussian from copulas.univariate.selection import select_univariate +from scipy.stats import truncnorm def test_select_univariate_bimodal(): diff --git a/tests/unit/univariate/test_student_t.py b/tests/unit/univariate/test_student_t.py index a98e4003..352e5dcc 100644 --- a/tests/unit/univariate/test_student_t.py +++ b/tests/unit/univariate/test_student_t.py @@ -1,9 +1,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import t - from copulas.univariate.student_t import StudentTUnivariate +from scipy.stats import t class TestStudentTUnivariate(TestCase): diff --git a/tests/unit/univariate/test_truncated_gaussian.py b/tests/unit/univariate/test_truncated_gaussian.py index 8107de92..432bfa82 100644 --- a/tests/unit/univariate/test_truncated_gaussian.py +++ b/tests/unit/univariate/test_truncated_gaussian.py @@ -3,9 +3,8 @@ from unittest.mock import patch import numpy as np -from scipy.stats import truncnorm - from copulas.univariate.truncated_gaussian import TruncatedGaussian +from scipy.stats import truncnorm class TestTruncatedGaussian(TestCase): diff --git a/tests/unit/univariate/test_uniform.py b/tests/unit/univariate/test_uniform.py index ca81d896..a8d49d48 100644 --- a/tests/unit/univariate/test_uniform.py +++ b/tests/unit/univariate/test_uniform.py @@ -1,9 +1,8 @@ from unittest import TestCase import numpy as np -from scipy.stats import uniform - from copulas.univariate.uniform import UniformUnivariate +from scipy.stats import uniform class TestUniformUnivariate(TestCase):