Skip to content

Add retire warning to legacy code #863

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

Merged
merged 9 commits into from
Jul 14, 2020
Merged
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
2 changes: 2 additions & 0 deletions torchtext/data/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import torch
import warnings


class Batch(object):
Expand All @@ -19,6 +20,7 @@ class Batch(object):

def __init__(self, data=None, dataset=None, device=None):
"""Create a Batch from a list of examples."""
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
if data is not None:
self.batch_size = len(data)
self.dataset = dataset
Expand Down
6 changes: 6 additions & 0 deletions torchtext/data/example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from functools import reduce
import warnings


class Example(object):
Expand All @@ -9,6 +10,7 @@ class Example(object):
"""
@classmethod
def fromJSON(cls, data, fields):
warnings.warn('Example class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.', UserWarning)
ex = cls()
obj = json.loads(data)

Expand Down Expand Up @@ -47,6 +49,7 @@ def reducer(obj, key):

@classmethod
def fromdict(cls, data, fields):
warnings.warn('Example class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.', UserWarning)
ex = cls()
for key, vals in fields.items():
if key not in data:
Expand All @@ -62,6 +65,7 @@ def fromdict(cls, data, fields):

@classmethod
def fromCSV(cls, data, fields, field_to_index=None):
warnings.warn('Example class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.', UserWarning)
if field_to_index is None:
return cls.fromlist(data, fields)
else:
Expand All @@ -71,6 +75,7 @@ def fromCSV(cls, data, fields, field_to_index=None):

@classmethod
def fromlist(cls, data, fields):
warnings.warn('Example class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.', UserWarning)
ex = cls()
for (name, field), val in zip(fields, data):
if field is not None:
Expand All @@ -86,6 +91,7 @@ def fromlist(cls, data, fields):

@classmethod
def fromtree(cls, data, fields, subtrees=False):
warnings.warn('Example class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.', UserWarning)
try:
from nltk.tree import Tree
except ImportError:
Expand Down
7 changes: 6 additions & 1 deletion torchtext/data/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from itertools import chain
import torch
from tqdm import tqdm

import warnings
from .dataset import Dataset
from .pipeline import Pipeline
from .utils import get_tokenizer, dtype_to_attr, is_tokenizer_serializable
Expand Down Expand Up @@ -33,6 +33,7 @@ class RawField(object):
"""

def __init__(self, preprocessing=None, postprocessing=None, is_target=False):
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
self.preprocessing = preprocessing
self.postprocessing = postprocessing
self.is_target = is_target
Expand Down Expand Up @@ -146,6 +147,7 @@ def __init__(self, sequential=True, use_vocab=True, init_token=None,
batch_first=False, pad_token="<pad>", unk_token="<unk>",
pad_first=False, truncate_first=False, stop_words=None,
is_target=False):
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
self.sequential = sequential
self.use_vocab = use_vocab
self.init_token = init_token
Expand Down Expand Up @@ -365,6 +367,7 @@ def numericalize(self, arr, device=None):

class ReversibleField(Field):
def __init__(self, **kwargs):
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
if kwargs.get('tokenize') is list:
self.use_revtok = False
else:
Expand Down Expand Up @@ -411,6 +414,7 @@ class SubwordField(ReversibleField):
vocab_cls = SubwordVocab

def __init__(self, **kwargs):
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
kwargs['tokenize'] = 'subword'
if 'unk_token' not in kwargs:
kwargs['unk_token'] = '�'
Expand Down Expand Up @@ -491,6 +495,7 @@ def __init__(self, nesting_field, use_vocab=True, init_token=None, eos_token=Non
postprocessing=None, tokenize=None, tokenizer_language='en',
include_lengths=False, pad_token='<pad>',
pad_first=False, truncate_first=False):
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
if isinstance(nesting_field, NestedField):
raise ValueError('nesting field must not be another NestedField')
if nesting_field.include_lengths:
Expand Down
3 changes: 2 additions & 1 deletion torchtext/data/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random

import logging

import warnings
import torch
from .utils import RandomShuffler
from .batch import Batch
Expand Down Expand Up @@ -45,6 +45,7 @@ def __init__(self, dataset, batch_size, sort_key=None, device=None,
batch_size_fn=None, train=True,
repeat=False, shuffle=None, sort=None,
sort_within_batch=None):
warnings.warn('{} class will be retired in the 0.8.0 release and moved to torchtext.legacy. Please see 0.7.0 release notes for further information.'.format(self.__class__.__name__), UserWarning)
self.batch_size, self.train, self.dataset = batch_size, train, dataset
self.batch_size_fn = batch_size_fn
self.iterations = 0
Expand Down