From 5855adbc03d108404d445e8c941efd3448bd30ba Mon Sep 17 00:00:00 2001 From: FengZiYjun Date: Tue, 4 Dec 2018 23:30:54 +0800 Subject: [PATCH] fix FieldArray bug: do type check only when is_target or is_input is True --- fastNLP/core/fieldarray.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fastNLP/core/fieldarray.py b/fastNLP/core/fieldarray.py index 2340cd13..e1d7a032 100644 --- a/fastNLP/core/fieldarray.py +++ b/fastNLP/core/fieldarray.py @@ -45,8 +45,9 @@ class FieldArray(object): @is_input.setter def is_input(self, value): - self.pytype = self._type_detection(self.content) - self.dtype = self._map_to_np_type(self.pytype) + if value is True: + self.pytype = self._type_detection(self.content) + self.dtype = self._map_to_np_type(self.pytype) self._is_input = value @property @@ -55,8 +56,9 @@ class FieldArray(object): @is_target.setter def is_target(self, value): - self.pytype = self._type_detection(self.content) - self.dtype = self._map_to_np_type(self.pytype) + if value is True: + self.pytype = self._type_detection(self.content) + self.dtype = self._map_to_np_type(self.pytype) self._is_target = value def _type_detection(self, content):