Skip to content

Commit

Permalink
Merge pull request #9 from tudo-astroparticlephysics/pypi_upload
Browse files Browse the repository at this point in the history
Pypi upload
  • Loading branch information
lwitthaus authored Jan 11, 2024
2 parents b16e8e6 + 0568b57 commit ea35946
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 85 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy to PyPi

on:
push:
tags:
- 'v*'

jobs:
pypi:
name: Publish packages to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/funfolding
permissions:
id-token: write

steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install dependencies
run: |
pip install -U build
- name: Build package
run: python -m build

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ want to install the available packages via `conda` first.
matplotlib
numpy
pymc3
scikit-learn>=0.18.1
scikit-learn>=0.19.0
scipy
six
```

### Installing
Expand Down
17 changes: 3 additions & 14 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -83,18 +83,7 @@


# -- Options for HTML output ----------------------------------------------
try:
import sphinx_rtd_theme
except ImportError:
print('No sphinx_rtd_theme found! Default theme is used!')
else:
html_theme = "sphinx_rtd_theme"

html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -105,7 +94,7 @@
# 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 = ['_static']


# -- Options for HTMLHelp output ------------------------------------------
Expand Down
72 changes: 22 additions & 50 deletions funfolding/binning/tree_sklearn_based.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import numpy as np
import copy
from distutils.version import StrictVersion

import sklearn
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
from sklearn.ensemble import AdaBoostClassifier, AdaBoostRegressor

from ._binning import Binning
import warnings


old_sklean = StrictVersion("0.19.0") >= StrictVersion(sklearn.__version__)


def __sample_uniform__(y, sample_weight=None, random_state=None):
"""Function used to sample a uniform distribution from a binned y.
Expand Down Expand Up @@ -298,28 +293,16 @@ def __init__(self,
self.uniform = uniform

if regression:
if old_sklean:
if min_impurity_decrease != 0.:
warnings.warn('min_impurity_decrease is supported '
' only in sklearn version >= 0.19.0')
self.tree = DecisionTreeRegressor(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
max_features=max_features,
min_weight_fraction_leaf=min_weight_fraction_leaf,
random_state=random_state)
else:
self.tree = DecisionTreeRegressor(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
max_features=max_features,
min_impurity_decrease=min_impurity_decrease,
min_weight_fraction_leaf=min_weight_fraction_leaf,
random_state=random_state)
self.tree = DecisionTreeRegressor(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
max_features=max_features,
min_impurity_decrease=min_impurity_decrease,
min_weight_fraction_leaf=min_weight_fraction_leaf,
random_state=random_state,
)
if boosted in ['linear', 'square', 'exponential']:
self.boosted = AdaBoostRegressor(
base_estimator=self.tree,
Expand All @@ -336,35 +319,24 @@ def __init__(self,
else:
self.boosted = None
else:
if old_sklean:
if min_impurity_decrease != 0.:
warnings.warn('min_impurity_decrease is supported '
' only in sklearn version >= 0.19.0')
self.tree = DecisionTreeClassifier(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
max_features=max_features,
min_weight_fraction_leaf=min_weight_fraction_leaf,
random_state=random_state)
else:
self.tree = DecisionTreeClassifier(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
max_features=max_features,
min_weight_fraction_leaf=min_weight_fraction_leaf,
min_impurity_decrease=min_impurity_decrease,
random_state=random_state)
self.tree = DecisionTreeClassifier(
max_depth=max_depth,
min_samples_split=min_samples_split,
min_samples_leaf=min_samples_leaf,
max_leaf_nodes=max_leaf_nodes,
max_features=max_features,
min_weight_fraction_leaf=min_weight_fraction_leaf,
min_impurity_decrease=min_impurity_decrease,
random_state=random_state,
)
if boosted in ['SAMME', 'SAMME.R']:
self.boosted = AdaBoostClassifier(
base_estimator=self.tree,
n_estimators=n_estimators,
learning_rate=learning_rate,
algorithm=boosted,
random_state=random_state)
random_state=random_state,
)
elif boosted is not None:
raise ValueError(
'\'boosted\' should be None for no boosting '
Expand Down
3 changes: 1 addition & 2 deletions funfolding/model/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from scipy import linalg
from scipy import stats
from numpy.linalg import svd
import six


class Model(object):
Expand Down Expand Up @@ -1174,7 +1173,7 @@ def generate_fit_x0(self, vec_g, vec_f_0=None, size=None):
x0_i = vec_x_0_def[x0_slice]
if sample_x0 is None:
pos_x0_i = x0_i
elif isinstance(sample_x0, six.string_types):
elif isinstance(sample_x0, str):
if sample_x0 == 'poisson':
pos_x0_i = self.random_state.poisson(x0_i,
size=size)
Expand Down
3 changes: 1 addition & 2 deletions funfolding/solution/_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
from scipy import linalg
from scipy.optimize import minimize
import six

import emcee

Expand Down Expand Up @@ -323,7 +322,7 @@ def fit(self,
sigma_limits=error_interval_sigma_limits,
n_nuissance=self.model.n_nuissance_parameters)
if thin is not None:
if isinstance(thin, six.string_types):
if isinstance(thin, str):
if thin.lower() == 'autocorr':
thin = int(np.max(autocorr_time[0]) + 0.5)
if isinstance(thin, int):
Expand Down
5 changes: 2 additions & 3 deletions funfolding/solution/likelihood.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import six

from ..model import LinearModel, Model

Expand Down Expand Up @@ -108,7 +107,7 @@ def initialize(self,

if self.tau is None:
self._tau = None
elif isinstance(self.tau, six.string_types):
elif isinstance(self.tau, str):
if self._tau.lower() == 'None':
self._tau = None
else:
Expand Down Expand Up @@ -142,7 +141,7 @@ def initialize(self,
"callable!")
if self._tau is not None:
m_C = None
if isinstance(self.C, six.string_types):
if isinstance(self.C, str):
if self.C.lower() == 'thikonov' or self.C.lower() == '2':
m_C = create_C_thikonov(
eff_f_length)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"
25 changes: 15 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()


extras_require = {
'tests': ['pytest'],
'docs': ['sphinx', 'sphinx-rtd-theme'],
}
extras_require['all'] = extras_require['tests'] + extras_require['docs']

setup(
name='funfolding',
version='0.2.2',
version='0.3.0',

description='Having fun with unfolding.',
long_description=long_description,
Expand All @@ -30,10 +37,12 @@

'License :: OSI Approved :: MIT License',

'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
python_requires=">= 3.9, <3.12a0",
keywords='unfolding',
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
install_requires=[
Expand All @@ -42,12 +51,8 @@
'matplotlib',
'numpy',
'pymc3',
'scikit-learn>=0.18.1',
'scikit-learn>=0.19.0',
'scipy',
'six>=1.1',
],
extras_require={
':python_version == "2.7"': ['futures'],
'tests': ['pytest'],
},
extras_require=extras_require,
)

0 comments on commit ea35946

Please sign in to comment.