Skip to content
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

Support for recursive datatypes #866

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ jobs:
pip3 install --pre torch -f "${{ steps.pytorch_channel.outputs.value }}"
- name: Install dependencies
run: |

pip3 install requests mypy==0.990 graphviz numpy
pip3 install -r requirements.txt
pip3 install mypy==0.960 numpy types-requests

- name: Build TorchData
run: |
pip3 install .
Expand All @@ -66,7 +68,7 @@ jobs:
run: |
set -eux
STATUS=
if ! mypy --config=mypy.ini; then
if ! mypy --config=mypy.ini --enable-recursive-aliases --install-types --non-interactive; then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also like to point out that, --install-types --non-interactive will install the missing package stubs hence slower.

Quoting relevant part from the above documentation link :- This is somewhat slower than explicitly installing stubs before running mypy, since it may type check your code twice – the first time to find the missing stubs, and the second time to type check your code properly after mypy has installed the stubs.

I don't think downloading the package stubs would be a bottleneck; but if it is, then we could think of using cached installations. (just a suggestion)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing the idea. I think it's fine for now as torchdata is still a small package. We might want to investigate if we have noticed significant overhead.

STATUS=fail
fi
if [ -n "$STATUS" ]; then
Expand Down
2 changes: 1 addition & 1 deletion torchdata/datapipes/iter/util/randomsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
self._rng = random.Random(self._seed)
self._lengths: List[int] = []

def draw(self) -> T:
def draw(self) -> T: # type: ignore
selected_key = self._rng.choices(self.keys, self.weights)[0]
index = self.key_to_index[selected_key]
self.weights[index] -= 1
Expand Down
2 changes: 1 addition & 1 deletion torchdata/datapipes/iter/util/tfrecordloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def prod(xs): # type: ignore[no-redef]
# Note, reccursive types not supported by mypy at the moment
# TODO(640): uncomment as soon as it becomes supported
# https://github.com/python/mypy/issues/731
# BinaryData = Union[str, List['BinaryData']]
BinaryData = Union[str, List["BinaryData"]]
TFRecordBinaryData = Union[str, List[str], List[List[str]], List[List[List[Any]]]]
TFRecordExampleFeature = Union[torch.Tensor, List[torch.Tensor], TFRecordBinaryData]
TFRecordExample = Dict[str, TFRecordExampleFeature]
Expand Down