From fa769c0bc91cd794ec136eb5fb471a49fbb78773 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Fri, 5 Aug 2022 12:18:18 +0200 Subject: [PATCH] Make Scheme.labels a property --- audformat/core/scheme.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/audformat/core/scheme.py b/audformat/core/scheme.py index a041bf78..33d990e4 100644 --- a/audformat/core/scheme.py +++ b/audformat/core/scheme.py @@ -155,15 +155,30 @@ def __init__( ) dtype = dtype_labels - self.dtype = dtype - r"""Data type""" - self.labels = labels - r"""List of labels""" + self._dtype = dtype + self._labels = labels + self.minimum = minimum if self.is_numeric else None r"""Minimum value""" self.maximum = maximum if self.is_numeric else None r"""Maximum value""" + @property + def dtype(self) -> str: + r"""Data type""" + return self._dtype + + @property + def labels(self) -> typing.Optional[typing.Union[dict, list, str]]: + r"""Labels of scheme""" + if ( + self._labels is not None + and not isinstance(self._labels, str) + ): + return self._labels.copy() + else: + return self._labels + @property def is_numeric(self) -> bool: r"""Check if data type is numeric. @@ -327,7 +342,7 @@ def replace_labels( f"'{dtype_labels}'" ) - self.labels = labels + self._labels = labels if self._db is not None and self._id is not None: labels = self._labels_to_list(labels)