New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Hinting and Type Aliasing Draft PR #964
Conversation
If people want to contribute and help: Things I'd like others to do some research on. Typing / Aliasing nested pandas data frames. Typing numpy arrays. |
So, my big question is: what is a "good" way to do runtime type checks or hints, using "implicit type definitions" such as "a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,32 @@ | |||
from typing import Union, Tuple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this fits better into sktime/base/
rather than sktime/utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. happy to move it. Just picked somewhere for the time being.
@@ -1,11 +1,13 @@ | |||
#!/usr/bin/env python3 -u | |||
# -*- coding: utf-8 -*- | |||
# copyright: sktime developers, BSD-3-Clause License (see LICENSE file) | |||
|
|||
from __future__ import annotations # this is for type hinting | |||
from typing import Dict | |||
__author__ = ["Markus Löning"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move imports above the __author__
and __all__
info?
So i think this is a pretty open question within python world. |
Thought Id jump in and just add my take on this. So first off just some links to typing packages I've used in other projects and are extremely useful we may want to consider (I've linked these to @ABostrom in the past) : So just quickly how I structure my types for projects is:
My motivation for doing it this way doesn't come from Python. As @ABostrom said above it's quite an open conversation currently in the Python community, so I decided to structure my types like I would as if I was using Typescript. Typescript is similar in the sense it's built on top of a language that doesn't have types (javascript) . Typescript is just a wrapper around your javascript which allows type checking to be done at run time. Once checks are complete the wrapper is removed and plain javascript is outputted. This is essentially doing the same thing python typing is doing (although Typescript is more established and more powerful for typing stuff). While I certainly don't think this is the final end solution potentially drawing some of how Typescript does types could be of benefit just because it is so well established and used. |
maybe also useful to point out this old enhancement proposal of mine: look at the "type checking" at the bottom, this could be its own python package. Regarding the main content, I think we're moving towards the nested architecture (see foreceasting base class) instead of the decorator architecture discussed in the STEP. |
@ABostrom, @chrisholder, do you know anything good for declarative typing? E.g., I want to assign a type As opposed to inferring type based on some pre-defined or pre-existing type system. |
Not 100% sure what you mean but did this example of what I thought you mean. You can't guarentee that someone will assign the correct value but you can definitely add additional checks. I also saw this in the python documentation: |
@chrisholder, see #980 and the linked extension proposal no.5 therein - hope that makes it clearer |
This has been depcreated and abandoned, based on pandas and numpy pushing this internally. |
The only dependency I would like to propose we add is : https://github.com/python/mypy Mypy can be sued to staticly check the type hints we add to our programs, and I think can be a big push in the direction of code correctness validation. |
That sounds like a good idea, having this run in the CI pipelines would be important to ensure that that code/type hints make sense |
Sorry, accidentally closed the PR, reopened now. |
hi @ABostrom , there is conflict with main now, can we close this PR and reopen it from a branch? That way I can tidy it up |
should we perhaps complete the |
Alright, the I would suggest: let's move the I think |
@ABostrom, ping |
I'll close this for now, feel free to re-open if you want to pick this up again, I've also started playing around with it here #1679 |
Reference Issues/PRs
This is a draft PR for type hinting in SKtime.
It's super WIP, but I wanted to start work on it. so others could see my ideas, and comment as I muddle my way through.
I needed a long summer project I could work on slowly.
What should a reviewer concentrate their feedback on?
Typing the data containers is tricky, as we have some different formats.
Everything else should be straightforward.