Skip to content

Commit

Permalink
chore: change package name to correspond to name of the library
Browse files Browse the repository at this point in the history
  • Loading branch information
elmomoilanen committed Apr 25, 2024
1 parent 998ed1a commit d754f08
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 93 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class SampDistError(Exception):
"""Base class for `sampdist` package errors."""
"""Base class for errors."""


class StatisticError(SampDistError):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Implements some commonly used statistics library compatibly.
"""Implements some commonly used statistics.
Implemented functions
- mean
Expand Down
37 changes: 37 additions & 0 deletions docs/source/bootstrap_sampling_distribution.rst
Original file line number Diff line number Diff line change
@@ -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:
33 changes: 7 additions & 26 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -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 --------------------------------------------------------------
Expand All @@ -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']
html_static_path = []
3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sampdist
========
Bootstrap-sampling-distribution
================================

.. toctree::
:maxdepth: 4

sampdist
bootstrap_sampling_distribution
37 changes: 0 additions & 37 deletions docs/source/sampdist.rst

This file was deleted.

6 changes: 3 additions & 3 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import numpy as np

from sampdist import plotting
from bootstrap_sampling_distribution import plotting


@pytest.fixture
Expand Down Expand Up @@ -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())

Expand All @@ -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())

Expand Down
6 changes: 3 additions & 3 deletions tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d754f08

Please sign in to comment.