From d754f088676bb971540f7523959422fbe321c811 Mon Sep 17 00:00:00 2001 From: Elmo Moilanen <49366097+elmomoilanen@users.noreply.github.com> Date: Thu, 25 Apr 2024 19:33:14 +0300 Subject: [PATCH] chore: change package name to correspond to name of the library --- .github/workflows/main.yml | 6 +-- README.md | 10 ++--- .../__init__.py | 11 +++--- .../errors.py | 2 +- .../plotting.py | 0 .../sampling.py | 6 +-- .../statistics.py | 2 +- .../bootstrap_sampling_distribution.rst | 37 +++++++++++++++++++ docs/source/conf.py | 33 ++++------------- docs/source/index.rst | 3 +- docs/source/modules.rst | 6 +-- docs/source/sampdist.rst | 37 ------------------- tests/test_plotting.py | 6 +-- tests/test_sampling.py | 6 +-- tests/test_statistics.py | 2 +- 15 files changed, 74 insertions(+), 93 deletions(-) rename {sampdist => bootstrap_sampling_distribution}/__init__.py (68%) rename {sampdist => bootstrap_sampling_distribution}/errors.py (83%) rename {sampdist => bootstrap_sampling_distribution}/plotting.py (100%) rename {sampdist => bootstrap_sampling_distribution}/sampling.py (98%) rename {sampdist => bootstrap_sampling_distribution}/statistics.py (98%) create mode 100644 docs/source/bootstrap_sampling_distribution.rst delete mode 100644 docs/source/sampdist.rst diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b54da87..fc92550 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,10 +44,8 @@ jobs: - name: Lint with flake8 run: | - poetry run flake8 ./sampdist/* \ - --count --select=E9,F63,F7,F82 --show-source --statistics - poetry run flake8 ./sampdist/* --max-line-length=100 \ - --ignore=E501,F401 --max-complexity=10 --count --exit-zero + poetry run flake8 ./bootstrap_sampling_distribution/* --count --select=E9,F63,F7,F82 --show-source --statistics + poetry run flake8 ./bootstrap_sampling_distribution/* --max-line-length=100 --ignore=E501,F401 --max-complexity=10 --count --exit-zero - name: Check typing run: poetry run mypy . diff --git a/README.md b/README.md index c007547..15dfd29 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ First let's consider a case where we assume X to be a numerical data with shape ```python import numpy as np -from sampdist import SampDist +from bootstrap_sampling_distribution import SampDist # One-dimensional statistics should be defined with axis=1 def quantile(x): return np.quantile(x, q=0.1, axis=1) @@ -69,10 +69,10 @@ The following figure represents a possible result of the plot call. In addition For the second example, let's consider the estimation process of the sampling distribution for a multidimensional statistic, e.g. Pearson's linear correlation. Keeping the mentioned assumptions regarding data X, following code estimates the sampling distribution and in the final row of the snippet, renders a histogram plot similarly to the figure above. Compared to the previous example, notice the difference in estimation process of the chosen statistic. Here the multidimensional statistic, Pearson's correlation, requires two attributes (columns) of the data X as input (a data slice of shape n x 2) and produces a single output which is the value of correlation. ```python -from sampdist import SampDist +from bootstrap_sampling_distribution import SampDist # Import custom implementation of the Pearson's correlation -from sampdist import corr_pearson +from bootstrap_sampling_distribution import corr_pearson samp = SampDist(corr_pearson) @@ -84,11 +84,11 @@ samp.plot() ![](docs/bootstrap_distribution_corr.png) -Notice that the validity of the statistic is checked when calling the estimate method. If this check fails, a *StatisticError* exception will be raised. Furthermore, if the estimated sampling distribution is degenerate (e.g. data almost identical), a *BcaError* exception gets raised (in this case you may try to use True for the smooth_bootstrap parameter). Both exceptions inherit from class *SampDistError* which can be imported directly from the sampdist namespace. +Notice that the validity of the statistic is checked when calling the estimate method. If this check fails, a *StatisticError* exception will be raised. Furthermore, if the estimated sampling distribution is degenerate (e.g. data almost identical), a *BcaError* exception gets raised (in this case you may try to use True for the smooth_bootstrap parameter). Both exceptions inherit from class *SampDistError* which can be imported directly from the bootstrap_sampling_distribution namespace. ## Docs ## -Render the documentation as HTML with the following command +Render the documentation as HTML files with the following command ```bash poetry run sphinx-build -b html docs/source/ docs/build/html diff --git a/sampdist/__init__.py b/bootstrap_sampling_distribution/__init__.py similarity index 68% rename from sampdist/__init__.py rename to bootstrap_sampling_distribution/__init__.py index c4e4da4..367e542 100644 --- a/sampdist/__init__.py +++ b/bootstrap_sampling_distribution/__init__.py @@ -1,6 +1,7 @@ -"""Quick guide to sampdist package. +"""Quick guide to Bootstrap-sampling-distribution package. + +This package contains the following modules -Package contains the following modules - errors - plotting - sampling @@ -14,10 +15,10 @@ compatibly in the `statistics` module. """ -from sampdist.errors import SampDistError -from sampdist.sampling import SampDist +from bootstrap_sampling_distribution.errors import SampDistError +from bootstrap_sampling_distribution.sampling import SampDist -from sampdist.statistics import ( +from bootstrap_sampling_distribution.statistics import ( mean, geometric_mean, harmonic_mean, diff --git a/sampdist/errors.py b/bootstrap_sampling_distribution/errors.py similarity index 83% rename from sampdist/errors.py rename to bootstrap_sampling_distribution/errors.py index ef76bf1..2a1f042 100644 --- a/sampdist/errors.py +++ b/bootstrap_sampling_distribution/errors.py @@ -2,7 +2,7 @@ class SampDistError(Exception): - """Base class for `sampdist` package errors.""" + """Base class for errors.""" class StatisticError(SampDistError): diff --git a/sampdist/plotting.py b/bootstrap_sampling_distribution/plotting.py similarity index 100% rename from sampdist/plotting.py rename to bootstrap_sampling_distribution/plotting.py diff --git a/sampdist/sampling.py b/bootstrap_sampling_distribution/sampling.py similarity index 98% rename from sampdist/sampling.py rename to bootstrap_sampling_distribution/sampling.py index 065c3e9..4fc4cb3 100644 --- a/sampdist/sampling.py +++ b/bootstrap_sampling_distribution/sampling.py @@ -69,7 +69,7 @@ class SampDist: from the statistics module could also be used. >>> import numpy as np - >>> from sampdist import SampDist + >>> from bootstrap_sampling_distribution import SampDist >>> def quantile(x): return np.quantile(x, q=0.1, axis=1) >>> samp = SampDist(quantile, alpha=99, smooth_bootstrap=True) >>> samp.estimate(X[:, [0,2]]) # estimate sampling distribution for columns 0 and 2 @@ -82,8 +82,8 @@ class SampDist: is imported from the statistics module where it has been implemented to accept 3-d data as for input (SampDist requires extra dimension to be inserted in this case). - >>> from sampdist import SampDist - >>> from sampdist.statistics import corr_pearson + >>> from bootstrap_sampling_distribution import SampDist + >>> from bootstrap_sampling_distribution.statistics import corr_pearson >>> samp = SampDist(corr_pearson) >>> samp.estimate(X[:, :2], multid=True) # estimate sampling distribution for columns 0 and 1 >>> samp.se, samp.ci # standard error and BCa confidence interval diff --git a/sampdist/statistics.py b/bootstrap_sampling_distribution/statistics.py similarity index 98% rename from sampdist/statistics.py rename to bootstrap_sampling_distribution/statistics.py index e9cbbb9..b00a9db 100644 --- a/sampdist/statistics.py +++ b/bootstrap_sampling_distribution/statistics.py @@ -1,4 +1,4 @@ -"""Implements some commonly used statistics library compatibly. +"""Implements some commonly used statistics. Implemented functions - mean diff --git a/docs/source/bootstrap_sampling_distribution.rst b/docs/source/bootstrap_sampling_distribution.rst new file mode 100644 index 0000000..0c4f886 --- /dev/null +++ b/docs/source/bootstrap_sampling_distribution.rst @@ -0,0 +1,37 @@ +Bootstrap-sampling-distribution package +======================================= + +Submodules +---------- + +bootstrap_sampling_distribution.plotting module +----------------------------------------------- + +.. automodule:: bootstrap_sampling_distribution.plotting + :members: + :undoc-members: + :show-inheritance: + +bootstrap_sampling_distribution.sampling module +----------------------------------------------- + +.. automodule:: bootstrap_sampling_distribution.sampling + :members: + :undoc-members: + :show-inheritance: + +bootstrap_sampling_distribution.statistics module +------------------------------------------------- + +.. automodule:: bootstrap_sampling_distribution.statistics + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: bootstrap_sampling_distribution + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/conf.py b/docs/source/conf.py index 246f599..c4e25f5 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,7 +1,6 @@ # Configuration file for the Sphinx documentation builder. # -# This file only contains a selection of the most common options. For a full -# list see the documentation: +# For the full list of built-in configuration values, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- @@ -14,44 +13,26 @@ import sys sys.path.insert(0, os.path.abspath('../..')) - # -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = 'Bootstrap-sampling-distribution' -copyright = '2022, Elmo Moilanen' +copyright = '2024, Elmo Moilanen' author = 'Elmo Moilanen' -# The full version, including alpha/beta/rc tags -release = '1.0.0' - - # -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.napoleon' ] -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. +templates_path = [] exclude_patterns = [] - # -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# html_theme = 'sphinx_rtd_theme' - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] \ No newline at end of file +html_static_path = [] diff --git a/docs/source/index.rst b/docs/source/index.rst index 479d805..c6cdda4 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,4 +1,5 @@ -.. Bootstrap-sampling-distribution documentation master file, created by sphinx-quickstart. +.. Bootstrap-sampling-distribution documentation master file, created by + sphinx-quickstart on Thu Apr 25 19:05:46 2024. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. diff --git a/docs/source/modules.rst b/docs/source/modules.rst index fee2653..aa0e1fe 100644 --- a/docs/source/modules.rst +++ b/docs/source/modules.rst @@ -1,7 +1,7 @@ -sampdist -======== +Bootstrap-sampling-distribution +================================ .. toctree:: :maxdepth: 4 - sampdist + bootstrap_sampling_distribution diff --git a/docs/source/sampdist.rst b/docs/source/sampdist.rst deleted file mode 100644 index 1cb8f51..0000000 --- a/docs/source/sampdist.rst +++ /dev/null @@ -1,37 +0,0 @@ -sampdist package -================ - -Submodules ----------- - -sampdist.plotting module ------------------------- - -.. automodule:: sampdist.plotting - :members: - :undoc-members: - :show-inheritance: - -sampdist.sampling module ------------------------- - -.. automodule:: sampdist.sampling - :members: - :undoc-members: - :show-inheritance: - -sampdist.statistics module --------------------------- - -.. automodule:: sampdist.statistics - :members: - :undoc-members: - :show-inheritance: - -Module contents ---------------- - -.. automodule:: sampdist - :members: - :undoc-members: - :show-inheritance: diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 2505a8b..01438f7 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -5,7 +5,7 @@ import pytest import numpy as np -from sampdist import plotting +from bootstrap_sampling_distribution import plotting @pytest.fixture @@ -37,7 +37,7 @@ def plot_config(): } -@patch("sampdist.plotting.plt", autospec=True) +@patch("bootstrap_sampling_distribution.plotting.plt", autospec=True) def test_plot_estimates_without_comparison(mock_plt, plotter, plot_data, plot_config): mock_plt.subplots.return_value = (MagicMock(), MagicMock()) @@ -53,7 +53,7 @@ def test_plot_estimates_without_comparison(mock_plt, plotter, plot_data, plot_co assert plotter._set_annotation.call_count == 3 -@patch("sampdist.plotting.plt", autospec=True) +@patch("bootstrap_sampling_distribution.plotting.plt", autospec=True) def test_plot_estimates_with_comparison(mock_plt, plotter, plot_data, plot_config): mock_plt.subplots.return_value = (MagicMock(), MagicMock()) diff --git a/tests/test_sampling.py b/tests/test_sampling.py index 1ce7e11..47be388 100644 --- a/tests/test_sampling.py +++ b/tests/test_sampling.py @@ -5,9 +5,9 @@ import numpy as np import pytest -from sampdist import SampDist +from bootstrap_sampling_distribution import SampDist -from sampdist import ( +from bootstrap_sampling_distribution import ( mean, geometric_mean, harmonic_mean, @@ -25,7 +25,7 @@ corr_spearman, ) -from sampdist.errors import StatisticError, BcaError +from bootstrap_sampling_distribution.errors import StatisticError, BcaError # all one dimensional statistics except those behind factory function all_one_dim_statistics = ( diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 73dc125..a268524 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -6,7 +6,7 @@ import pytest from scipy.stats import pearsonr, spearmanr -from sampdist import ( +from bootstrap_sampling_distribution import ( trimmed_mean_factory, quantile_factory, corr_pearson,