Skip to content

Commit

Permalink
Merge pull request #9 from cjekel/fixsort
Browse files Browse the repository at this point in the history
prep for 1.0.3 -- hotfix for sorting
  • Loading branch information
cjekel authored Mar 27, 2023
2 parents b47aad4 + fe3603f commit 7df3f19
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.3] - 2023-03-26
### Changed
- Fixed a bug introduced in `1.0.2` where `checks.assert_2d_sort` was not sorting

## [1.0.2] - 2023-03-25
### Changed
- Fixed a bug where a sort function was modifying the input data array. This could have unintended consequence for a user without their knowledge. See [PR](https://github.com/cjekel/tolerance_interval_py/pull/7). Thanks to Jed Ludlow](https://github.com/jedludlow)
Expand Down
6 changes: 4 additions & 2 deletions docs/checks.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ <h1 class="title">Module <code>toleranceinterval.checks</code></h1>
elif x.ndim &gt; 2:
raise ValueError(&#39;x can not be more than 2 dimensions&#39;)
# Prevent modifications to input data by copying x before sorting.
x.copy().sort()
x = x.copy()
x.sort()
return x</code></pre>
</details>
</section>
Expand All @@ -90,7 +91,8 @@ <h2 class="section-title" id="header-functions">Functions</h2>
elif x.ndim &gt; 2:
raise ValueError(&#39;x can not be more than 2 dimensions&#39;)
# Prevent modifications to input data by copying x before sorting.
x.copy().sort()
x = x.copy()
x.sort()
return x</code></pre>
</details>
</dd>
Expand Down
12 changes: 6 additions & 6 deletions docs/hk.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ <h1 class="title">Module <code>toleranceinterval.hk</code></h1>
# create a dummy variable v
self.v = Symbol(&#39;v&#39;, nonzero=True, rational=True, positive=True)
# check that p, g, n, j are valid
if not(p &lt; 0.5 and p &gt; 0.):
if not (p &lt; 0.5 and p &gt; 0.):
self.invalid_value(p, &#39;p&#39;)
else:
self.p = p
if not(g &gt; 0. and g &lt; 1.):
if not (g &gt; 0. and g &lt; 1.):
self.invalid_value(g, &#39;g&#39;)
else:
self.g = g
self.n = int(n)
if not(j &lt; n and j &gt; -1):
if not (j &lt; n and j &gt; -1):
self.invalid_value(j, &#39;j&#39;)
else:
self.j = int(j)
Expand Down Expand Up @@ -439,16 +439,16 @@ <h2 id="references">References</h2>
# create a dummy variable v
self.v = Symbol(&#39;v&#39;, nonzero=True, rational=True, positive=True)
# check that p, g, n, j are valid
if not(p &lt; 0.5 and p &gt; 0.):
if not (p &lt; 0.5 and p &gt; 0.):
self.invalid_value(p, &#39;p&#39;)
else:
self.p = p
if not(g &gt; 0. and g &lt; 1.):
if not (g &gt; 0. and g &lt; 1.):
self.invalid_value(g, &#39;g&#39;)
else:
self.g = g
self.n = int(n)
if not(j &lt; n and j &gt; -1):
if not (j &lt; n and j &gt; -1):
self.invalid_value(j, &#39;j&#39;)
else:
self.j = int(j)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ def test_assert_2d_sort(self):
# print(x_new, x_sort[idx])
self.assertTrue(np.isclose(x_new, x_sort[idx]))

def test_x_unmodified(self):
for i in range(10):
x = np.random.random(5)
x = checks.numpy_array(x)
x.sort()
x[0] = 12919.1
xnew = checks.assert_2d_sort(x)
# print(xnew[0, -1], 12919.1)
self.assertTrue(np.isclose(xnew[0, -1], 12919.1))
self.assertTrue(np.isclose(x[0], 12919.1))


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion toleranceinterval/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.3
3 changes: 2 additions & 1 deletion toleranceinterval/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def assert_2d_sort(x):
elif x.ndim > 2:
raise ValueError('x can not be more than 2 dimensions')
# Prevent modifications to input data by copying x before sorting.
x.copy().sort()
x = x.copy()
x.sort()
return x

0 comments on commit 7df3f19

Please sign in to comment.