Check if list/tuple is empty in ListsOfScalarsDataAdapter.

Helps to avoid "IndexError: list index out of range" given an empty list to the can_handle method.

PiperOrigin-RevId: 346046184
Change-Id: I75a25f6595b0ff43226440881a2c4990dfbbb6b2
This commit is contained in:
A. Unique TensorFlower 2020-12-07 02:15:04 -08:00 committed by TensorFlower Gardener
parent 41c7a26d13
commit c6b0ec6bcf
2 changed files with 2 additions and 1 deletions

View File

@ -619,7 +619,7 @@ class ListsOfScalarsDataAdapter(DataAdapter):
def _is_list_of_scalars(inp):
if isinstance(inp, (float, int, str, bytes, bytearray)):
return True
if isinstance(inp, (list, tuple)):
if isinstance(inp, (list, tuple)) and inp:
return ListsOfScalarsDataAdapter._is_list_of_scalars(inp[0])
return False

View File

@ -1096,6 +1096,7 @@ class ListsOfScalarsDataAdapterTest(DataAdapterTestBase):
self.assertFalse(self.adapter_cls.can_handle(self.dataset_input))
self.assertFalse(self.adapter_cls.can_handle(self.generator_input))
self.assertFalse(self.adapter_cls.can_handle(self.sequence_input))
self.assertFalse(self.adapter_cls.can_handle([]))
class TestUtils(keras_parameterized.TestCase):