Re: [Numpy-discussion] Best fit linear piecewise function?
Multivariate Adaptive Regression Splines might fit the bill? Implemented for python as py-earth: https://github.com/scikit-learn-contrib/py-earth. On 6/2/21 2:22 AM, Chris Barker wrote: Do any of you know of code for finding an optimum linear piecewise fit to a set of points? Somethin like what is described in this article: https://www.hindawi.com/journals/mpe/2015/876862/ <https://www.hindawi.com/journals/mpe/2015/876862/> At a glance, that looked just hard enough to code up that I'm hoping someone has already done it :-) -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov <mailto:chris.bar...@noaa.gov> ___ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion -- Vincent Schut Remote Sensing Software Engineer +31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands Linkedin <https://www.linkedin.com/company/satelligence/>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com> ___ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] mypy false positives
Hi all, I've got a question about numpy typing. We have our own internal codebase that heavily depends on numpy, and we're trying to get the number of mypy errors down. Many of the remaining mypy errors are actually numpy false positives. I hoped that with the numpy 1.22.0 release these would be fixed, as there ought to be many typing improvements in that version, but apparently they're not? I'm asking here to check if this is just still a work in progress and we should be patient, or if there's something wrong on our side...? Some typical false positives are: "finfo[float32]" has no attribute "tiny" Module has no attribute "count_nonzero" Module has no attribute "rot90" Module has no attribute "asfortranarray" Module has no attribute "isfinite" Module has no attribute "any" Module has no attribute "histogram"; maybe "histogramdd"? Module has no attribute "bitwise_or" Module has no attribute "bitwise_and" Module has no attribute "indices" Module has no attribute "pad" versions: python 3.8.10; numpy 1.22.0; mypy 0.930 -- Vincent Schut Remote Sensing Software Engineer +31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands Linkedin <https://www.linkedin.com/company/satelligence/>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com> ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com
[Numpy-discussion] Re: mypy false positives
Hi Bas, thank you! I checked and indeed: I was surprised to see the outdated "data-science-types" package installed. I removed it and the amount of mypy errors decreased dramatically. I'm so glad I asked, I already spent way too much time at googling ;-) Thanks again for the fast and accurate reply! Vincent. On 1/7/22 15:58, bas van beek wrote: Hi Vincent, Could it be that you're overriding numpy's type annotations with those from an external stub-only package? The functions that you mentioned have been annotated as being in the main namespace ever since the 1.20 release; the error message for `finfo` in particular makes me suspicious. For reference: ``` finfo_obj = np.finfo(np.float64) reveal_type(finfo_obj.tiny)# Revealed type is "numpy.floating*[numpy.typing._64Bit*]" reveal_type(finfo_obj.foo)# "finfo[floating[_64Bit]]" has no attribute "foo" ``` Regards, Bas van Beek -------- *From:* Vincent Schut *Sent:* 07 January 2022 15:38 *To:* numpy-discussion@python.org *Subject:* [Numpy-discussion] mypy false positives Hi all, I've got a question about numpy typing. We have our own internal codebase that heavily depends on numpy, and we're trying to get the number of mypy errors down. Many of the remaining mypy errors are actually numpy false positives. I hoped that with the numpy 1.22.0 release these would be fixed, as there ought to be many typing improvements in that version, but apparently they're not? I'm asking here to check if this is just still a work in progress and we should be patient, or if there's something wrong on our side...? Some typical false positives are: "finfo[float32]" has no attribute "tiny" Module has no attribute "count_nonzero" Module has no attribute "rot90" Module has no attribute "asfortranarray" Module has no attribute "isfinite" Module has no attribute "any" Module has no attribute "histogram"; maybe "histogramdd"? Module has no attribute "bitwise_or" Module has no attribute "bitwise_and" Module has no attribute "indices" Module has no attribute "pad" versions: python 3.8.10; numpy 1.22.0; mypy 0.930 -- Vincent Schut Remote Sensing Software Engineer +31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands Linkedin <https://www.linkedin.com/company/satelligence/ <https://www.linkedin.com/company/satelligence/>>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com <http://www.satelligence.com><http://www.satelligence.com>> ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ <https://mail.python.org/mailman3/lists/numpy-discussion.python.org/> Member address: bas.vanb...@hotmail.com ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: sc...@satelligence.com -- Vincent Schut Remote Sensing Software Engineer +31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands Linkedin <https://www.linkedin.com/company/satelligence/>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com> ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com
[Numpy-discussion] ndarray typing advise
Hi, I'm having a hard(ish) time adding the right type annotations to some numpy-using code. I hope someone more knowledgeable can give me some advise. Specifically, the following questions pop up: - How do I correctly type a ndarray as being an array of float64, such that mypy can infer that when I index this array, the result is actually a float (currently I consistently get "Any" after indexing)? - How can I get compatibility between np.floating and builtin.float? Currently, some numpy functions are typed to return np.floating[Any] (e.g. np.linalg.norm). When I feed this result into something that is supposed to receive a builtin.float, mypy complains. Is an explicit cast(float, ) the prefered way to gain compatibility here? versions: numpy: 1.22.0 python: 3.8.10 (unfortunately we're limited to this version) mypy: 0.931 Thanks! Vincent. -- Vincent Schut Remote Sensing Software Engineer +31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands Linkedin <https://www.linkedin.com/company/satelligence/>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com> ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com
[Numpy-discussion] Re: ndarray typing advise
Sorry to bump my own issue, but I wonder if just no-one knows, or if it has been overlooked, or maybe I did not explain my questions right? Should I rather ask this on SO? Or should I just be more patient...? Thanks! Vincent. On 1/13/22 11:43, Vincent Schut wrote: Hi, I'm having a hard(ish) time adding the right type annotations to some numpy-using code. I hope someone more knowledgeable can give me some advise. Specifically, the following questions pop up: - How do I correctly type a ndarray as being an array of float64, such that mypy can infer that when I index this array, the result is actually a float (currently I consistently get "Any" after indexing)? - How can I get compatibility between np.floating and builtin.float? Currently, some numpy functions are typed to return np.floating[Any] (e.g. np.linalg.norm). When I feed this result into something that is supposed to receive a builtin.float, mypy complains. Is an explicit cast(float, ) the prefered way to gain compatibility here? versions: numpy: 1.22.0 python: 3.8.10 (unfortunately we're limited to this version) mypy: 0.931 Thanks! Vincent. -- Vincent Schut Remote Sensing Software Engineer +31 302272679 ~ Maliebaan 22 | 3581CP | Utrecht | Netherlands Linkedin <https://www.linkedin.com/company/satelligence/>~ satelligence.com <http://www.satelligence.com><http://www.satelligence.com> ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com