bs-python-utils 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. bs_python_utils-0.0.1/LICENSE +21 -0
  2. bs_python_utils-0.0.1/PKG-INFO +71 -0
  3. bs_python_utils-0.0.1/README.md +47 -0
  4. bs_python_utils-0.0.1/bs_python_utils/Timer.py +76 -0
  5. bs_python_utils-0.0.1/bs_python_utils/__init__.py +0 -0
  6. bs_python_utils-0.0.1/bs_python_utils/bs_altair.py +927 -0
  7. bs_python_utils-0.0.1/bs_python_utils/bs_logging.py +100 -0
  8. bs_python_utils-0.0.1/bs_python_utils/bs_mathstr.py +130 -0
  9. bs_python_utils-0.0.1/bs_python_utils/bs_mem.py +148 -0
  10. bs_python_utils-0.0.1/bs_python_utils/bs_opt.py +518 -0
  11. bs_python_utils-0.0.1/bs_python_utils/bs_plots.py +2 -0
  12. bs_python_utils-0.0.1/bs_python_utils/bs_seaborn.py +174 -0
  13. bs_python_utils-0.0.1/bs_python_utils/bs_sparse_gaussian.py +46 -0
  14. bs_python_utils-0.0.1/bs_python_utils/bsmplutils.py +34 -0
  15. bs_python_utils-0.0.1/bs_python_utils/bsnputils.py +957 -0
  16. bs_python_utils-0.0.1/bs_python_utils/bssputils.py +79 -0
  17. bs_python_utils-0.0.1/bs_python_utils/bsstats.py +463 -0
  18. bs_python_utils-0.0.1/bs_python_utils/bsutils.py +363 -0
  19. bs_python_utils-0.0.1/bs_python_utils/distance_covariances.py +258 -0
  20. bs_python_utils-0.0.1/bs_python_utils/example_opt.py +71 -0
  21. bs_python_utils-0.0.1/bs_python_utils/examples_altair.py +195 -0
  22. bs_python_utils-0.0.1/bs_python_utils/examples_distance_covariances.py +32 -0
  23. bs_python_utils-0.0.1/bs_python_utils/examples_mem.py +25 -0
  24. bs_python_utils-0.0.1/bs_python_utils/examples_seaborn.py +37 -0
  25. bs_python_utils-0.0.1/bs_python_utils/examples_sklearn.py +33 -0
  26. bs_python_utils-0.0.1/bs_python_utils/pandas_utils.py +239 -0
  27. bs_python_utils-0.0.1/bs_python_utils/sklearn_utils.py +74 -0
  28. bs_python_utils-0.0.1/pyproject.toml +100 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023, Bernard Salanie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.1
2
+ Name: bs-python-utils
3
+ Version: 0.0.1
4
+ Summary: my Python utilities
5
+ Home-page: https://github.com/bsalanie/bs-python-utils
6
+ Author: Bernard Salanie
7
+ Author-email: fbsalanie@columbia.edu
8
+ Requires-Python: >=3.8,<4.0
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Requires-Dist: altair (>=4.2.2,<5.0.0)
15
+ Requires-Dist: altair-saver (>=0.5.0,<0.6.0)
16
+ Requires-Dist: matplotlib (>=3.7.1,<4.0.0)
17
+ Requires-Dist: scikit-learn (>=1.2.2,<2.0.0)
18
+ Requires-Dist: seaborn (>=0.12.2,<0.13.0)
19
+ Requires-Dist: statsmodels (>=0.13.5,<0.14.0)
20
+ Requires-Dist: vega-datasets (>=0.9.0,<0.10.0)
21
+ Project-URL: Documentation, https://bsalanie.github.io/bs-python-utils/
22
+ Project-URL: Repository, https://github.com/bsalanie/bs-python-utils
23
+ Description-Content-Type: text/markdown
24
+
25
+ # bs-python-utils
26
+
27
+ [![Release](https://img.shields.io/github/v/release/bsalanie/bs-python-utils)](https://img.shields.io/github/v/release/bsalanie/bs-python-utils)
28
+ [![Build status](https://img.shields.io/github/actions/workflow/status/bsalanie/bs-python-utils/main.yml?branch=main)](https://github.com/bsalanie/bs-python-utils/actions/workflows/main.yml?query=branch%3Amain)
29
+ [![codecov](https://codecov.io/gh/bsalanie/bs-python-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/bsalanie/bs-python-utils)
30
+ [![Commit activity](https://img.shields.io/github/commit-activity/m/bsalanie/bs-python-utils)](https://img.shields.io/github/commit-activity/m/bsalanie/bs-python-utils)
31
+ [![License](https://img.shields.io/github/license/bsalanie/bs-python-utils)](https://img.shields.io/github/license/bsalanie/bs-python-utils)
32
+
33
+ my Python utilities
34
+
35
+ - **Github repository**: <https://github.com/bsalanie/bs-python-utils/>
36
+ - **Documentation** <https://bsalanie.github.io/bs-python-utils/>
37
+
38
+ ## Getting started with your project
39
+
40
+ First, create a repository on GitHub with the same name as this project, and then run the following commands:
41
+
42
+ ``` bash
43
+ git init -b main
44
+ git add .
45
+ git commit -m "init commit"
46
+ git remote add origin git@github.com:bsalanie/bs-python-utils.git
47
+ git push -u origin main
48
+ ```
49
+
50
+ Finally, install the environment and the pre-commit hooks with
51
+
52
+ ```bash
53
+ make install
54
+ ```
55
+
56
+ You are now ready to start development on your project! The CI/CD
57
+ pipeline will be triggered when you open a pull request, merge to main,
58
+ or when you create a new release.
59
+
60
+
61
+ ## Releasing a new version
62
+
63
+ <!-- - Create an API Token on [Pypi](https://pypi.org/).
64
+ - Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting
65
+ [this page](https://github.com/bsalanie/bs-python-utils/settings/secrets/actions/new). -->
66
+ - Create a [new release](https://github.com/bsalanie/bs-python-utils/releases/new) on Github.
67
+ Create a new tag in the form ``*.*.*``.
68
+
69
+ ---
70
+
71
+ Repository initiated with [fpgmaas/cookiecutter-poetry](https://github.com/fpgmaas/cookiecutter-poetry).
@@ -0,0 +1,47 @@
1
+ # bs-python-utils
2
+
3
+ [![Release](https://img.shields.io/github/v/release/bsalanie/bs-python-utils)](https://img.shields.io/github/v/release/bsalanie/bs-python-utils)
4
+ [![Build status](https://img.shields.io/github/actions/workflow/status/bsalanie/bs-python-utils/main.yml?branch=main)](https://github.com/bsalanie/bs-python-utils/actions/workflows/main.yml?query=branch%3Amain)
5
+ [![codecov](https://codecov.io/gh/bsalanie/bs-python-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/bsalanie/bs-python-utils)
6
+ [![Commit activity](https://img.shields.io/github/commit-activity/m/bsalanie/bs-python-utils)](https://img.shields.io/github/commit-activity/m/bsalanie/bs-python-utils)
7
+ [![License](https://img.shields.io/github/license/bsalanie/bs-python-utils)](https://img.shields.io/github/license/bsalanie/bs-python-utils)
8
+
9
+ my Python utilities
10
+
11
+ - **Github repository**: <https://github.com/bsalanie/bs-python-utils/>
12
+ - **Documentation** <https://bsalanie.github.io/bs-python-utils/>
13
+
14
+ ## Getting started with your project
15
+
16
+ First, create a repository on GitHub with the same name as this project, and then run the following commands:
17
+
18
+ ``` bash
19
+ git init -b main
20
+ git add .
21
+ git commit -m "init commit"
22
+ git remote add origin git@github.com:bsalanie/bs-python-utils.git
23
+ git push -u origin main
24
+ ```
25
+
26
+ Finally, install the environment and the pre-commit hooks with
27
+
28
+ ```bash
29
+ make install
30
+ ```
31
+
32
+ You are now ready to start development on your project! The CI/CD
33
+ pipeline will be triggered when you open a pull request, merge to main,
34
+ or when you create a new release.
35
+
36
+
37
+ ## Releasing a new version
38
+
39
+ <!-- - Create an API Token on [Pypi](https://pypi.org/).
40
+ - Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting
41
+ [this page](https://github.com/bsalanie/bs-python-utils/settings/secrets/actions/new). -->
42
+ - Create a [new release](https://github.com/bsalanie/bs-python-utils/releases/new) on Github.
43
+ Create a new tag in the form ``*.*.*``.
44
+
45
+ ---
46
+
47
+ Repository initiated with [fpgmaas/cookiecutter-poetry](https://github.com/fpgmaas/cookiecutter-poetry).
@@ -0,0 +1,76 @@
1
+ """
2
+ utilities to time code
3
+ """
4
+
5
+ import time
6
+ from functools import wraps
7
+ from typing import Any, Callable, Iterable
8
+
9
+
10
+ def timeit(func: Callable) -> Callable:
11
+ """
12
+ Decorator to time a function
13
+ """
14
+
15
+ @wraps(func)
16
+ def wrapper(*args: Iterable, **kwargs: dict) -> Any:
17
+ start = time.perf_counter()
18
+ result = func(*args, **kwargs)
19
+ end = time.perf_counter()
20
+ print(f"{func.__name__} executed in {end - start:.6f} seconds")
21
+ return result
22
+
23
+ return wrapper
24
+
25
+
26
+ class Timer:
27
+ """
28
+ A timer that can be started, stopped, and reset as needed by the user.
29
+ It keeps track of the total elapsed time in the `elapsed` attribute::
30
+
31
+ with Timer() as t:
32
+ ....
33
+ print(f"... took {t.elapsed} seconds")
34
+
35
+ use `Timer(time.process_time)` to get only CPU time.
36
+
37
+ can also do::
38
+
39
+ t = Timer()
40
+ t.start()
41
+ t.stop()
42
+ t.start() # will add to the same counter
43
+ t.stop()
44
+ print(f"{t.elapsed} seconds total")
45
+ """
46
+
47
+ def __init__(self, func: Callable = time.perf_counter) -> None:
48
+ self.elapsed = 0.0
49
+ self._func = func
50
+ self._start = None
51
+
52
+ def start(self) -> None:
53
+ if self._start is not None:
54
+ raise RuntimeError("Already started")
55
+ self._start = self._func()
56
+
57
+ def stop(self) -> None:
58
+ if self._start is None:
59
+ raise RuntimeError("Not started")
60
+ end = self._func()
61
+ self.elapsed += end - self._start
62
+ self._start = None
63
+
64
+ def reset(self) -> None:
65
+ self.elapsed = 0.0
66
+
67
+ @property
68
+ def running(self) -> bool:
69
+ return self._start is not None
70
+
71
+ def __enter__(self) -> Any:
72
+ self.start()
73
+ return self
74
+
75
+ def __exit__(self, *args: Iterable) -> None:
76
+ self.stop()
File without changes