Skip to content

Correct pylint for translate datasets. #1649

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

Open
wants to merge 4 commits into
base: master
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
11 changes: 6 additions & 5 deletions tensorflow_datasets/translate/flores.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""Facebook Low Resource (FLoRes) machine translation benchmark dataset."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import collections

Expand Down Expand Up @@ -78,8 +74,12 @@ def __init__(self,
name=name,
description=description,
version=tfds.core.Version(
"1.1.0",
"1.0.0",
"New split API (https://tensorflow.org/datasets/splits)"),
supported_versions=[
tfds.core.Version(
"0.0.3", experiments={tfds.core.Experiment.S3: False}),
],
**kwargs)
self.text_encoder_config = (
text_encoder_config or tfds.features.text.TextEncoderConfig())
Expand Down Expand Up @@ -126,6 +126,7 @@ def _vocab_text_gen(self, files, language):
yield ex[language]

def _split_generators(self, dl_manager):
"""Generate Splits"""
dl_dir = dl_manager.download_and_extract(_DATA_URL)

source, target = self.builder_config.language_pair
Expand Down
17 changes: 6 additions & 11 deletions tensorflow_datasets/translate/wmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""WMT: Translate dataset."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import codecs
import functools
import gzip
Expand Down Expand Up @@ -60,7 +55,7 @@
]


class SubDataset(object):
class SubDataset(object): # pylint: disable=R0205
"""Class to keep track of information on a sub-dataset of WMT."""

def __init__(self, name, target, sources, url, path, manual_dl_files=None):
Expand Down Expand Up @@ -102,12 +97,11 @@ def _inject_language(self, src, strings):
def _format_string(s):
if "{0}" in s and "{1}" and "{src}" in s:
return s.format(*sorted([src, self.target]), src=src)
elif "{0}" in s and "{1}" in s:
if "{0}" in s and "{1}" in s:
return s.format(*sorted([src, self.target]))
elif "{src}" in s:
if "{src}" in s:
return s.format(src=src)
else:
return s
return s
return [_format_string(s) for s in strings]

def get_url(self, src):
Expand Down Expand Up @@ -675,6 +669,7 @@ def _vocab_text_gen(self, split_subsets, extraction_map, language):
yield ex[language]

def _split_generators(self, dl_manager):
"""Generate Splits"""
source, _ = self.builder_config.language_pair

def _check_manual_files(ds):
Expand Down Expand Up @@ -939,7 +934,7 @@ def _parse_czeng(*paths, **kwargs):
re_block = re.compile(r"^[^-]+-b(\d+)-\d\d[tde]")
with tf.io.gfile.GFile(filter_path) as f:
bad_blocks = {
blk for blk in re.search(
blk for blk in re.search( # pylint: disable=R1721
r"qw{([\s\d]*)}", f.read()).groups()[0].split()
}
logging.info(
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_datasets/translate/wmt19_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
# Lint as: python3
"""Tests for WMT translate dataset module."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow_datasets import testing
from tensorflow_datasets.translate import wmt19


class TranslateDeEnWmt19Test(testing.DatasetBuilderTestCase):
"""Create testing.DatasetBuilderTestCase for de-en test"""
DATASET_CLASS = wmt19.Wmt19Translate
BUILDER_CONFIG_NAMES_TO_TEST = ["de-en"]
OVERLAPPING_SPLITS = ["validation"]
Expand All @@ -46,6 +44,7 @@ class TranslateDeEnWmt19Test(testing.DatasetBuilderTestCase):


class TranslateCsEnWmt19Test(testing.DatasetBuilderTestCase):
"""Create testing.DatasetBuilderTestCase for cs-en test"""
DATASET_CLASS = wmt19.Wmt19Translate
BUILDER_CONFIG_NAMES_TO_TEST = ["cs-en"]
OVERLAPPING_SPLITS = ["validation"]
Expand All @@ -65,5 +64,6 @@ class TranslateCsEnWmt19Test(testing.DatasetBuilderTestCase):
"validation": 2,
}


if __name__ == "__main__":
testing.test_main()
14 changes: 8 additions & 6 deletions tensorflow_datasets/translate/wmt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@


class TranslateWmtCustomConfigTest(testing.DatasetBuilderTestCase):

"""Create testing.DatasetBuilderTestCase for de-en test"""
@classmethod
def setUpClass(cls):
super(TranslateWmtCustomConfigTest, cls).setUpClass()
def setup_class(cls):
"""Create configs """
super(TranslateWmtCustomConfigTest, cls).setup_class()

config = wmt.WmtConfig(
name="small",
Expand All @@ -47,8 +48,8 @@ def setUpClass(cls):
wmt.WmtTranslate.BUILDER_CONFIGS = [config]

@classmethod
def tearDownClass(cls):
super(TranslateWmtCustomConfigTest, cls).tearDownClass()
def teardown_class(cls):
super(TranslateWmtCustomConfigTest, cls).teardown_class()
wmt.WmtTranslate.BUILDER_CONFIGS.pop()

DATASET_CLASS = wmt.WmtTranslate
Expand Down Expand Up @@ -81,8 +82,9 @@ def tearDownClass(cls):
}

def test_gzip_reading(self):
"""Testing gzip Reading"""
results = [
x for _, x in wmt._parse_parallel_sentences(
x for _, x in wmt._parse_parallel_sentences( # pylint: disable=protected-access
os.path.join(self.example_dir, "first.cs.gz"),
os.path.join(self.example_dir, "second.en.txt"))
]
Expand Down