Skip to content

Commit

Permalink
Merge pull request #7 from prjemian/6-math-domain-error
Browse files Browse the repository at this point in the history
Repair math domain error
  • Loading branch information
prjemian authored Feb 8, 2024
2 parents 7d4381e + fc325f2 commit befd250
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
- "3.9"
- "3.10" # not 3.10 which truncates to 3.1
- "3.11"
- "3.12"
max-parallel: 5

steps:
Expand All @@ -68,6 +69,7 @@ jobs:
- name: Run tests with pytest & coverage
run: |
set -vxeuo pipefail
coverage run --concurrency=thread --parallel-mode -m pytest -vvv .
coverage combine
coverage report --precision 3
Expand Down
16 changes: 13 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ Change History
release expected TBA

1.0.6 (developing)
******************
1.0.6 (developing)
******************

release expected TBA
release expected TBA

Fixes
--------------

* Fixed *math domain error* in standard deviation functions.

Maintenance
--------------

* Add Python 3.12

1.0.5
******
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
requires = ["setuptools>=61", "setuptools_scm[toml]>=8"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 115
target-version = ['py311']
target-version = ['py312']
include = '\.pyi?$'
exclude = '''
Expand Down
2 changes: 1 addition & 1 deletion pysumreg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# -----------------------------------------------------------------------------
# :author: Pete R. Jemian
# :email: [email protected]
# :copyright: (c) 2014-2022, Pete R. Jemian
# :copyright: (c) 2014-2024, Pete R. Jemian
#
# Distributed under the terms of the Creative Commons Attribution 4.0 International Public License.
#
Expand Down
8 changes: 6 additions & 2 deletions pysumreg/sum_registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def stddev_x(self):
.. math:: \sigma_x^2 = {{\sum{x^2} - \bar{x}\sum{x}} \over {n-1}}
"""
return math.sqrt((self.XX - self.mean_x * self.X) / (self.n - 1))
numerator = max(0, self.XX - self.mean_x * self.X)
denominator = self.n - 1
return math.sqrt(numerator / denominator)

@property
def stddev_y(self):
Expand All @@ -189,7 +191,9 @@ def stddev_y(self):
.. math:: \sigma_y^2 = {{\sum{y^2} - \bar{y}\sum{y}} \over {n-1}}
"""
return math.sqrt((self.YY - self.mean_y * self.Y) / (self.n - 1))
numerator = max(0, self.YY - self.mean_y * self.Y)
denominator = self.n - 1
return math.sqrt(numerator / denominator)

@property
def slope(self):
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ profile=black

[metadata]
name = pysumreg
copyright = 2022-2022, Pete R. Jemian
copyright = 2014-2024, Pete R. Jemian
description = Statistics of list of (x, y) pairs from calculator-style summation registers.
description_file = README.md
description_file_content_type = text/markdown
Expand All @@ -54,6 +54,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Astronomy
Topic :: Scientific/Engineering :: Bio-Informatics
Expand All @@ -70,7 +71,7 @@ classifiers =
# python_requires = >=3.8
packages = find:
setup_requires =
setuptools_scm[toml]>=6.2
setuptools_scm[toml]>=8

# Specify any package dependencies below. Examples shown
# None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# -----------------------------------------------------------------------------
# :author: Pete R. Jemian
# :email: [email protected]
# :copyright: (c) 2014-2022, Pete R. Jemian
# :copyright: (c) 2014-2024, Pete R. Jemian
#
# Distributed under the terms of the Creative Commons Attribution 4.0 International Public License.
#
Expand Down

0 comments on commit befd250

Please sign in to comment.