From e7a19f90ad78c2430be794da1ac9965e23a9b4fb Mon Sep 17 00:00:00 2001 From: Bert Palm <bert.palm@ufz.de> Date: Wed, 15 Apr 2020 05:32:07 +0200 Subject: [PATCH] exposed cast policy as property --- dios/dios.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dios/dios.py b/dios/dios.py index b5a0863..709e966 100644 --- a/dios/dios.py +++ b/dios/dios.py @@ -37,7 +37,7 @@ from typing import Union, Any class DictOfSeries: - f""" A data frame where every column has its own index. + """ A data frame where every column has its own index. DictOfSeries is a collection of pd.Series's which aim to be as close as possible similar to pd.DataFrame. The advantage over pd.DataFrame is, that every `column` has its own row-index, @@ -62,16 +62,17 @@ class DictOfSeries: if None, the index-type is inferred each time a series is inserted or deleted. - cast_policy : str {_CAST_POLICIES} + cast_policy : str Policy to use for down-casting an itype. """ def __init__(self, data=None, columns=None, index=None, itype=None, cast_policy='save', fastpath=False): - + + self.cast_policy = cast_policy + # we are called internally if fastpath: self._itype = itype or ObjItype - self._policy = cast_policy if data is not None: self._data = data else: @@ -94,10 +95,6 @@ class DictOfSeries: if itype is not None: self._itype = get_itype(itype) - if cast_policy not in _CAST_POLICIES: - raise ValueError(f"downcast_policy must be one of {_CAST_POLICIES}") - self._policy = cast_policy - cols = pd.Index([] if columns is None else columns) if not cols.is_unique: raise ValueError("columns must be unique") @@ -252,6 +249,16 @@ class DictOfSeries: raise ValueError(method) return res if res.is_unique else res.unique() + @property + def cast_policy(self): + return self._policy + + @cast_policy.setter + def cast_policy(self, policy): + if policy not in _CAST_POLICIES: + raise ValueError(f"policy must be one of {_CAST_POLICIES}") + self._policy = policy + @property def itype(self): if self._itype == 'INFER': -- GitLab