-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix LeastSquares for functions with more than two arguments (#1016)
Closes #974 - Fixes a bug in cost.LeastSquares which prevented the use with data that has more than two dimensions. - New unit test checks that cost.LeastSquares works with 3-dimensional data --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
cbd136b
commit 8022a33
Showing
10 changed files
with
160 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Get the latest Python release which is online.""" | ||
|
||
import urllib.request | ||
import re | ||
from html.parser import HTMLParser | ||
import gzip | ||
from packaging.version import Version | ||
|
||
|
||
class PythonVersionParser(HTMLParser): | ||
"""Specialized HTMLParser to get Python version number.""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.versions = set() | ||
self.found_version = False | ||
|
||
def handle_starttag(self, tag, attrs): | ||
"""Look for the right tag and store result in an attribute.""" | ||
if tag == "a": | ||
for attr in attrs: | ||
if attr[0] == "href" and "/downloads/release/python-" in attr[1]: | ||
self.found_version = True | ||
return | ||
|
||
def handle_data(self, data): | ||
"""Extract Python version from entry.""" | ||
if self.found_version: | ||
self.found_version = False | ||
match = re.search(r"Python (\d+\.\d+)", data) | ||
if match: | ||
self.versions.add(Version(match.group(1))) | ||
|
||
|
||
def versions(): | ||
"""Get all Python release versions.""" | ||
req = urllib.request.Request("https://www.python.org/downloads/") | ||
req.add_header("Accept-Encoding", "gzip") | ||
|
||
with urllib.request.urlopen(req) as response: | ||
raw = response.read() | ||
if response.info().get("Content-Encoding") == "gzip": | ||
raw = gzip.decompress(raw) | ||
html = raw.decode("utf-8") | ||
|
||
parser = PythonVersionParser() | ||
parser.feed(html) | ||
|
||
return parser.versions | ||
|
||
|
||
def latest(): | ||
"""Return version of latest Python release.""" | ||
return max(versions()) | ||
|
||
|
||
def main(): | ||
"""Print all discovered release versions.""" | ||
print(" ".join(str(x) for x in sorted(versions()))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters