Skip to content

Commit

Permalink
Fix backward compatibility breakage for interleave_cycle_length
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 309021159
  • Loading branch information
Conchylicultor authored and copybara-github committed Apr 29, 2020
1 parent 9ba5872 commit c702741
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions tensorflow_datasets/core/utils/read_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
import tensorflow.compat.v2 as tf


_OLD = 'interleave_parallel_reads'
_NEW = 'interleave_cycle_length'
_WARNING_MSG = (
'`{}` argument of `tfds.ReadConfig` is '
'deprecated and will be removed in a future version. Please use '
'`{}` instead.').format(_OLD, _NEW)


# TODO(tfds): Use dataclasses once Py2 support is dropped
@attr.s
class _ReadConfig(object):
Expand All @@ -45,6 +53,16 @@ class _ReadConfig(object):
interleave_block_length = attr.ib(default=16)
experimental_interleave_sort_fn = attr.ib(default=None)

@property
def interleave_parallel_reads(self):
logging.warning(_WARNING_MSG)
return self.interleave_cycle_length

@interleave_parallel_reads.setter
def interleave_parallel_reads(self, value):
logging.warning(_WARNING_MSG)
self.interleave_cycle_length = value


class ReadConfig(_ReadConfig):
"""Configures input reading pipeline.
Expand Down Expand Up @@ -74,14 +92,9 @@ class ReadConfig(_ReadConfig):
"""

def __init__(self, **kwargs):
old = 'interleave_parallel_reads'
new = 'interleave_cycle_length'
if old in kwargs:
if new in kwargs:
raise ValueError('Cannot set both {} and {}'.format(old, new))
logging.warning(
'`%s` argument of `tfds.ReadConfig` is '
'deprecated and will be removed in a future version. Please use '
'`%s` instead.', old, new)
kwargs[old] = kwargs.pop(new)
if _OLD in kwargs:
if _NEW in kwargs:
raise ValueError('Cannot set both {} and {}'.format(_OLD, _NEW))
logging.warning(_WARNING_MSG)
kwargs[_OLD] = kwargs.pop(_NEW)
super(ReadConfig, self).__init__(**kwargs)

0 comments on commit c702741

Please sign in to comment.