tab-dataset.tab_dataset.field_interface

The field_interface module is part of the tab-dataset package.

It contains the classes FieldInterface for Field entities.

For more information, see the user guide or the github repository.

  1# -*- coding: utf-8 -*-
  2"""
  3The `field_interface` module is part of the `tab-dataset` package.
  4
  5It contains the classes `FieldInterface` for Field entities.
  6
  7For more information, see the 
  8[user guide](https://loco-philippe.github.io/tab-dataset/docs/user_guide.html) 
  9or the [github repository](https://github.com/loco-philippe/tab-dataset).
 10"""
 11# %% declarations
 12import json
 13import datetime
 14import numpy as np
 15import pandas as pd
 16
 17from json_ntv.ntv import NtvSingle, NtvList
 18from json_ntv.ntv_util import NtvUtil
 19from tab_dataset.cfield import FieldError, Cutil, identity
 20
 21
 22class CborDecoder(json.JSONDecoder):
 23    ''' Cbor extension for integer keys (codification keys)'''
 24
 25    def __init__(self):
 26        json.JSONDecoder.__init__(self, object_hook=self.codecbor)
 27
 28    def codecbor(self, dic):
 29        ''' convert dict keys into integer and return new dict'''
 30        dic2 = {}
 31        for key, val in dic.items():
 32            try:
 33                key2 = int(key)
 34            except:
 35                key2 = key
 36            dic2[key2] = val
 37        return dic2
 38
 39
 40class FieldEncoder(json.JSONEncoder):
 41    """new json encoder for Field and Dataset"""
 42
 43    def default(self, o):
 44        if isinstance(o, datetime.datetime):
 45            return o.isoformat()
 46        option = {'encoded': False, 'format': 'json'}
 47        if o.__class__.__name__ in ('Dataset', 'TimeSlot', 'Ndataset', 'Sdataset'):
 48            return o.json(**option)
 49        # if issubclass(o.__class__, ESValue):
 50        #    return o.json(**option)
 51        try:
 52            return o.to_json(**option)
 53        except:
 54            try:
 55                return o.__to_json__()
 56            except:
 57                return json.JSONEncoder.default(self, o)
 58
 59
 60class FieldInterface:
 61    '''this class includes Field methods :
 62
 63    - `FieldInterface.json`
 64    - `FieldInterface.to_obj`
 65    - `FieldInterface.to_dict_obj`
 66    - `FieldInterface.to_numpy`
 67    - `FieldInterface.to_pandas`
 68    - `FieldInterface.vlist`
 69    - `FieldInterface.v_name`
 70    - `FieldInterface.vSimple`
 71    '''
 72
 73    def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs):
 74        '''
 75        Transform Field in a Numpy array.
 76
 77        *Parameters*
 78
 79        - **func** : function (default None) - function to apply for each value of the Field.
 80        If func is the 'index' string, values are replaced by raw values.
 81        - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None)
 82        - **kwargs** : parameters to apply to the func function
 83
 84        *Returns* : Numpy Array'''
 85        return self.to_pandas(func=func, codec=codec, npdtype=npdtype, numpy=True, **kwargs)
 86
 87    def to_ntv(self, modecodec='optimize', codecval=False, def_type=None,
 88               keys=None, parent=None, name=True, coef=None):
 89        '''Return a Ntv field value
 90
 91        *Parameters (kwargs)*
 92
 93        - **modecodec** : string (default 'optimize') - if 'full', index is with a full codec
 94        if 'default' index has keys, if 'optimize' keys are optimized,
 95        - **codecval** : boolean (default False) - if True, only list of codec values is included
 96        - **def_type** : string (default None) - default ntv_type for NtvList or NtvSet
 97        - **name** : boolean (default True) - if False, index name are not included
 98        - **keys** : list (default None) - used only with 'optimize' mode
 99        - **parent** : int or str (default None) - used only with 'optimize' mode
100
101        *Returns* : Ntv object'''
102        leng = len(self)
103        codec = self.l_to_n(self.codec)
104        decode_name, decode_type, sep = NtvUtil.from_obj_name(self.name)
105        decode_name = decode_name if sep == '::' else self.name
106        def_type = decode_type if sep == '::' else def_type
107        idxname = None if decode_name == '$default' or not name else decode_name
108        if leng == 1 or len(codec) == 1 and modecodec != 'full':
109            return NtvSingle(codec[0].ntv_value, idxname, codec[0].ntv_type)
110        if codecval or modecodec == 'nokeys':
111            return NtvList(codec, idxname, ntv_type=def_type)
112        if len(codec) == leng or modecodec == 'full':
113            return NtvList(self.values, idxname, ntv_type=def_type)
114        if modecodec == 'default':
115            return NtvList([NtvList(codec, ntv_type=def_type),
116                            NtvList(self.keys)], idxname)
117        if coef:
118            return NtvList([NtvList(codec, ntv_type=def_type),
119                            NtvList([coef])], idxname)
120        if modecodec == 'optimize':
121            ntv_value = [NtvList(codec, ntv_type=def_type)]
122            if not parent is None:
123                ntv_value.append(NtvSingle(parent))
124            if keys:
125                ntv_value.append(NtvList(keys))
126            elif parent is None:
127                ntv_value.append(NtvList(self.keys))
128            return NtvList(ntv_value, idxname)
129        return None
130
131    def to_pandas(self, func=None, codec=False, npdtype=None,
132                  series=True, index=True, numpy=False, **kwargs):
133        '''
134        Transform Field in a Pandas Series, Pandas DataFrame or Numpy array.
135
136        *Parameters*
137
138        - **func** : function (default None) - function to apply for each value of the Field.
139        If func is the 'index' string, values are replaced by raw values.
140        - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None)
141        - **series** : boolean (default True) - if True, return a Series.
142        If False return a DataFrame
143        - **index** : boolean (default True) - if True, index is keys.
144        - **numpy** : boolean (default False) - if True, return a Numpy array.
145        - **kwargs** : parameters to apply to the func function
146
147        *Returns* : Pandas Series, Pandas DataFrame, Numpy Array'''
148        if len(self) == 0:
149            raise FieldError("Dataset is empty")
150        if npdtype:
151            npdtype = np.dtype(npdtype)
152        else:
153            npdtype = 'object'
154        if func is None:
155            func = identity
156        if func == 'index':
157            return np.array(list(range(len(self))))
158        if not codec:
159            values = Cutil.funclist(self.values, func, **kwargs)
160        else:
161            values = Cutil.funclist(self._codec, func, **kwargs)
162        npdtype1 = npdtype
163        if isinstance(values[0], (datetime.datetime)):
164            npdtype1 = np.datetime64
165        pdindex = None
166        if index:
167            pdindex = self._keys
168        try:
169            if numpy:
170                return np.array(values, dtype=npdtype1)
171            if series:
172                return pd.Series(values, dtype=npdtype1,
173                                 index=pdindex, name=self.name)
174            return pd.DataFrame(pd.Series(values, dtype=npdtype1,
175                                          index=pdindex, name=self.name))
176        except:
177            if numpy:
178                return np.array(values, dtype=npdtype)
179            if series:
180                return pd.Series(values, dtype=npdtype,
181                                 index=pdindex, name=self.name)
182            return pd.DataFrame(pd.Series(values, dtype=npdtype,
183                                          index=pdindex, name=self.name))
184
185    def vlist(self, func, *args, extern=True, **kwargs):
186        '''
187        Apply a function to values and return the result.
188
189        *Parameters*
190
191        - **func** : function - function to apply to values
192        - **args, kwargs** : parameters for the function
193        - **extern** : if True, the function is apply to external values, else internal
194
195        *Returns* : list of func result'''
196        if extern:
197            return Cutil.funclist(self.val, func, *args, **kwargs)
198        return Cutil.funclist(self.values, func, *args, **kwargs)
199
200    def v_name(self):
201        '''Return the list of name of values'''
202        return [self.i_to_name(val) for val in self.values]
203
204    """def vSimple(self, string=False):
205        '''
206        Apply a vSimple function to values and return the result.
207
208        *Parameters*
209
210        - **string** : boolean(default False) - if True the values returned are string
211
212        *Returns* : list of vSimple values (string or not)'''
213        if string:
214            return json.dumps([util.cast(val, 'simple', string=string) for val in self.values],
215                              cls=ESValueEncoder)
216        return [util.cast(val, 'simple', string=string) for val in self.values]"""
class CborDecoder(json.decoder.JSONDecoder):
23class CborDecoder(json.JSONDecoder):
24    ''' Cbor extension for integer keys (codification keys)'''
25
26    def __init__(self):
27        json.JSONDecoder.__init__(self, object_hook=self.codecbor)
28
29    def codecbor(self, dic):
30        ''' convert dict keys into integer and return new dict'''
31        dic2 = {}
32        for key, val in dic.items():
33            try:
34                key2 = int(key)
35            except:
36                key2 = key
37            dic2[key2] = val
38        return dic2

Cbor extension for integer keys (codification keys)

CborDecoder()
26    def __init__(self):
27        json.JSONDecoder.__init__(self, object_hook=self.codecbor)

object_hook, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).

object_pairs_hook, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders. If object_hook is also defined, the object_pairs_hook takes priority.

parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).

parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).

parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid JSON numbers are encountered.

If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'.

def codecbor(self, dic):
29    def codecbor(self, dic):
30        ''' convert dict keys into integer and return new dict'''
31        dic2 = {}
32        for key, val in dic.items():
33            try:
34                key2 = int(key)
35            except:
36                key2 = key
37            dic2[key2] = val
38        return dic2

convert dict keys into integer and return new dict

Inherited Members
json.decoder.JSONDecoder
decode
raw_decode
class FieldEncoder(json.encoder.JSONEncoder):
41class FieldEncoder(json.JSONEncoder):
42    """new json encoder for Field and Dataset"""
43
44    def default(self, o):
45        if isinstance(o, datetime.datetime):
46            return o.isoformat()
47        option = {'encoded': False, 'format': 'json'}
48        if o.__class__.__name__ in ('Dataset', 'TimeSlot', 'Ndataset', 'Sdataset'):
49            return o.json(**option)
50        # if issubclass(o.__class__, ESValue):
51        #    return o.json(**option)
52        try:
53            return o.to_json(**option)
54        except:
55            try:
56                return o.__to_json__()
57            except:
58                return json.JSONEncoder.default(self, o)

new json encoder for Field and Dataset

def default(self, o):
44    def default(self, o):
45        if isinstance(o, datetime.datetime):
46            return o.isoformat()
47        option = {'encoded': False, 'format': 'json'}
48        if o.__class__.__name__ in ('Dataset', 'TimeSlot', 'Ndataset', 'Sdataset'):
49            return o.json(**option)
50        # if issubclass(o.__class__, ESValue):
51        #    return o.json(**option)
52        try:
53            return o.to_json(**option)
54        except:
55            try:
56                return o.__to_json__()
57            except:
58                return json.JSONEncoder.default(self, o)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this::

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
Inherited Members
json.encoder.JSONEncoder
JSONEncoder
encode
iterencode
class FieldInterface:
 61class FieldInterface:
 62    '''this class includes Field methods :
 63
 64    - `FieldInterface.json`
 65    - `FieldInterface.to_obj`
 66    - `FieldInterface.to_dict_obj`
 67    - `FieldInterface.to_numpy`
 68    - `FieldInterface.to_pandas`
 69    - `FieldInterface.vlist`
 70    - `FieldInterface.v_name`
 71    - `FieldInterface.vSimple`
 72    '''
 73
 74    def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs):
 75        '''
 76        Transform Field in a Numpy array.
 77
 78        *Parameters*
 79
 80        - **func** : function (default None) - function to apply for each value of the Field.
 81        If func is the 'index' string, values are replaced by raw values.
 82        - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None)
 83        - **kwargs** : parameters to apply to the func function
 84
 85        *Returns* : Numpy Array'''
 86        return self.to_pandas(func=func, codec=codec, npdtype=npdtype, numpy=True, **kwargs)
 87
 88    def to_ntv(self, modecodec='optimize', codecval=False, def_type=None,
 89               keys=None, parent=None, name=True, coef=None):
 90        '''Return a Ntv field value
 91
 92        *Parameters (kwargs)*
 93
 94        - **modecodec** : string (default 'optimize') - if 'full', index is with a full codec
 95        if 'default' index has keys, if 'optimize' keys are optimized,
 96        - **codecval** : boolean (default False) - if True, only list of codec values is included
 97        - **def_type** : string (default None) - default ntv_type for NtvList or NtvSet
 98        - **name** : boolean (default True) - if False, index name are not included
 99        - **keys** : list (default None) - used only with 'optimize' mode
100        - **parent** : int or str (default None) - used only with 'optimize' mode
101
102        *Returns* : Ntv object'''
103        leng = len(self)
104        codec = self.l_to_n(self.codec)
105        decode_name, decode_type, sep = NtvUtil.from_obj_name(self.name)
106        decode_name = decode_name if sep == '::' else self.name
107        def_type = decode_type if sep == '::' else def_type
108        idxname = None if decode_name == '$default' or not name else decode_name
109        if leng == 1 or len(codec) == 1 and modecodec != 'full':
110            return NtvSingle(codec[0].ntv_value, idxname, codec[0].ntv_type)
111        if codecval or modecodec == 'nokeys':
112            return NtvList(codec, idxname, ntv_type=def_type)
113        if len(codec) == leng or modecodec == 'full':
114            return NtvList(self.values, idxname, ntv_type=def_type)
115        if modecodec == 'default':
116            return NtvList([NtvList(codec, ntv_type=def_type),
117                            NtvList(self.keys)], idxname)
118        if coef:
119            return NtvList([NtvList(codec, ntv_type=def_type),
120                            NtvList([coef])], idxname)
121        if modecodec == 'optimize':
122            ntv_value = [NtvList(codec, ntv_type=def_type)]
123            if not parent is None:
124                ntv_value.append(NtvSingle(parent))
125            if keys:
126                ntv_value.append(NtvList(keys))
127            elif parent is None:
128                ntv_value.append(NtvList(self.keys))
129            return NtvList(ntv_value, idxname)
130        return None
131
132    def to_pandas(self, func=None, codec=False, npdtype=None,
133                  series=True, index=True, numpy=False, **kwargs):
134        '''
135        Transform Field in a Pandas Series, Pandas DataFrame or Numpy array.
136
137        *Parameters*
138
139        - **func** : function (default None) - function to apply for each value of the Field.
140        If func is the 'index' string, values are replaced by raw values.
141        - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None)
142        - **series** : boolean (default True) - if True, return a Series.
143        If False return a DataFrame
144        - **index** : boolean (default True) - if True, index is keys.
145        - **numpy** : boolean (default False) - if True, return a Numpy array.
146        - **kwargs** : parameters to apply to the func function
147
148        *Returns* : Pandas Series, Pandas DataFrame, Numpy Array'''
149        if len(self) == 0:
150            raise FieldError("Dataset is empty")
151        if npdtype:
152            npdtype = np.dtype(npdtype)
153        else:
154            npdtype = 'object'
155        if func is None:
156            func = identity
157        if func == 'index':
158            return np.array(list(range(len(self))))
159        if not codec:
160            values = Cutil.funclist(self.values, func, **kwargs)
161        else:
162            values = Cutil.funclist(self._codec, func, **kwargs)
163        npdtype1 = npdtype
164        if isinstance(values[0], (datetime.datetime)):
165            npdtype1 = np.datetime64
166        pdindex = None
167        if index:
168            pdindex = self._keys
169        try:
170            if numpy:
171                return np.array(values, dtype=npdtype1)
172            if series:
173                return pd.Series(values, dtype=npdtype1,
174                                 index=pdindex, name=self.name)
175            return pd.DataFrame(pd.Series(values, dtype=npdtype1,
176                                          index=pdindex, name=self.name))
177        except:
178            if numpy:
179                return np.array(values, dtype=npdtype)
180            if series:
181                return pd.Series(values, dtype=npdtype,
182                                 index=pdindex, name=self.name)
183            return pd.DataFrame(pd.Series(values, dtype=npdtype,
184                                          index=pdindex, name=self.name))
185
186    def vlist(self, func, *args, extern=True, **kwargs):
187        '''
188        Apply a function to values and return the result.
189
190        *Parameters*
191
192        - **func** : function - function to apply to values
193        - **args, kwargs** : parameters for the function
194        - **extern** : if True, the function is apply to external values, else internal
195
196        *Returns* : list of func result'''
197        if extern:
198            return Cutil.funclist(self.val, func, *args, **kwargs)
199        return Cutil.funclist(self.values, func, *args, **kwargs)
200
201    def v_name(self):
202        '''Return the list of name of values'''
203        return [self.i_to_name(val) for val in self.values]
204
205    """def vSimple(self, string=False):
206        '''
207        Apply a vSimple function to values and return the result.
208
209        *Parameters*
210
211        - **string** : boolean(default False) - if True the values returned are string
212
213        *Returns* : list of vSimple values (string or not)'''
214        if string:
215            return json.dumps([util.cast(val, 'simple', string=string) for val in self.values],
216                              cls=ESValueEncoder)
217        return [util.cast(val, 'simple', string=string) for val in self.values]"""

this class includes Field methods :

def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs):
74    def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs):
75        '''
76        Transform Field in a Numpy array.
77
78        *Parameters*
79
80        - **func** : function (default None) - function to apply for each value of the Field.
81        If func is the 'index' string, values are replaced by raw values.
82        - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None)
83        - **kwargs** : parameters to apply to the func function
84
85        *Returns* : Numpy Array'''
86        return self.to_pandas(func=func, codec=codec, npdtype=npdtype, numpy=True, **kwargs)

Transform Field in a Numpy array.

Parameters

  • func : function (default None) - function to apply for each value of the Field. If func is the 'index' string, values are replaced by raw values.
  • npdtype : string (default None) - numpy dtype for the Array ('object' if None)
  • kwargs : parameters to apply to the func function

Returns : Numpy Array

def to_ntv( self, modecodec='optimize', codecval=False, def_type=None, keys=None, parent=None, name=True, coef=None):
 88    def to_ntv(self, modecodec='optimize', codecval=False, def_type=None,
 89               keys=None, parent=None, name=True, coef=None):
 90        '''Return a Ntv field value
 91
 92        *Parameters (kwargs)*
 93
 94        - **modecodec** : string (default 'optimize') - if 'full', index is with a full codec
 95        if 'default' index has keys, if 'optimize' keys are optimized,
 96        - **codecval** : boolean (default False) - if True, only list of codec values is included
 97        - **def_type** : string (default None) - default ntv_type for NtvList or NtvSet
 98        - **name** : boolean (default True) - if False, index name are not included
 99        - **keys** : list (default None) - used only with 'optimize' mode
100        - **parent** : int or str (default None) - used only with 'optimize' mode
101
102        *Returns* : Ntv object'''
103        leng = len(self)
104        codec = self.l_to_n(self.codec)
105        decode_name, decode_type, sep = NtvUtil.from_obj_name(self.name)
106        decode_name = decode_name if sep == '::' else self.name
107        def_type = decode_type if sep == '::' else def_type
108        idxname = None if decode_name == '$default' or not name else decode_name
109        if leng == 1 or len(codec) == 1 and modecodec != 'full':
110            return NtvSingle(codec[0].ntv_value, idxname, codec[0].ntv_type)
111        if codecval or modecodec == 'nokeys':
112            return NtvList(codec, idxname, ntv_type=def_type)
113        if len(codec) == leng or modecodec == 'full':
114            return NtvList(self.values, idxname, ntv_type=def_type)
115        if modecodec == 'default':
116            return NtvList([NtvList(codec, ntv_type=def_type),
117                            NtvList(self.keys)], idxname)
118        if coef:
119            return NtvList([NtvList(codec, ntv_type=def_type),
120                            NtvList([coef])], idxname)
121        if modecodec == 'optimize':
122            ntv_value = [NtvList(codec, ntv_type=def_type)]
123            if not parent is None:
124                ntv_value.append(NtvSingle(parent))
125            if keys:
126                ntv_value.append(NtvList(keys))
127            elif parent is None:
128                ntv_value.append(NtvList(self.keys))
129            return NtvList(ntv_value, idxname)
130        return None

Return a Ntv field value

Parameters (kwargs)

  • modecodec : string (default 'optimize') - if 'full', index is with a full codec if 'default' index has keys, if 'optimize' keys are optimized,
  • codecval : boolean (default False) - if True, only list of codec values is included
  • def_type : string (default None) - default ntv_type for NtvList or NtvSet
  • name : boolean (default True) - if False, index name are not included
  • keys : list (default None) - used only with 'optimize' mode
  • parent : int or str (default None) - used only with 'optimize' mode

Returns : Ntv object

def to_pandas( self, func=None, codec=False, npdtype=None, series=True, index=True, numpy=False, **kwargs):
132    def to_pandas(self, func=None, codec=False, npdtype=None,
133                  series=True, index=True, numpy=False, **kwargs):
134        '''
135        Transform Field in a Pandas Series, Pandas DataFrame or Numpy array.
136
137        *Parameters*
138
139        - **func** : function (default None) - function to apply for each value of the Field.
140        If func is the 'index' string, values are replaced by raw values.
141        - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None)
142        - **series** : boolean (default True) - if True, return a Series.
143        If False return a DataFrame
144        - **index** : boolean (default True) - if True, index is keys.
145        - **numpy** : boolean (default False) - if True, return a Numpy array.
146        - **kwargs** : parameters to apply to the func function
147
148        *Returns* : Pandas Series, Pandas DataFrame, Numpy Array'''
149        if len(self) == 0:
150            raise FieldError("Dataset is empty")
151        if npdtype:
152            npdtype = np.dtype(npdtype)
153        else:
154            npdtype = 'object'
155        if func is None:
156            func = identity
157        if func == 'index':
158            return np.array(list(range(len(self))))
159        if not codec:
160            values = Cutil.funclist(self.values, func, **kwargs)
161        else:
162            values = Cutil.funclist(self._codec, func, **kwargs)
163        npdtype1 = npdtype
164        if isinstance(values[0], (datetime.datetime)):
165            npdtype1 = np.datetime64
166        pdindex = None
167        if index:
168            pdindex = self._keys
169        try:
170            if numpy:
171                return np.array(values, dtype=npdtype1)
172            if series:
173                return pd.Series(values, dtype=npdtype1,
174                                 index=pdindex, name=self.name)
175            return pd.DataFrame(pd.Series(values, dtype=npdtype1,
176                                          index=pdindex, name=self.name))
177        except:
178            if numpy:
179                return np.array(values, dtype=npdtype)
180            if series:
181                return pd.Series(values, dtype=npdtype,
182                                 index=pdindex, name=self.name)
183            return pd.DataFrame(pd.Series(values, dtype=npdtype,
184                                          index=pdindex, name=self.name))

Transform Field in a Pandas Series, Pandas DataFrame or Numpy array.

Parameters

  • func : function (default None) - function to apply for each value of the Field. If func is the 'index' string, values are replaced by raw values.
  • npdtype : string (default None) - numpy dtype for the Array ('object' if None)
  • series : boolean (default True) - if True, return a Series. If False return a DataFrame
  • index : boolean (default True) - if True, index is keys.
  • numpy : boolean (default False) - if True, return a Numpy array.
  • kwargs : parameters to apply to the func function

Returns : Pandas Series, Pandas DataFrame, Numpy Array

def vlist(self, func, *args, extern=True, **kwargs):
186    def vlist(self, func, *args, extern=True, **kwargs):
187        '''
188        Apply a function to values and return the result.
189
190        *Parameters*
191
192        - **func** : function - function to apply to values
193        - **args, kwargs** : parameters for the function
194        - **extern** : if True, the function is apply to external values, else internal
195
196        *Returns* : list of func result'''
197        if extern:
198            return Cutil.funclist(self.val, func, *args, **kwargs)
199        return Cutil.funclist(self.values, func, *args, **kwargs)

Apply a function to values and return the result.

Parameters

  • func : function - function to apply to values
  • args, kwargs : parameters for the function
  • extern : if True, the function is apply to external values, else internal

Returns : list of func result

def v_name(self):
201    def v_name(self):
202        '''Return the list of name of values'''
203        return [self.i_to_name(val) for val in self.values]

Return the list of name of values