python pandas groupby agg get lag1 - python

def lag1(x):
return x[(len(x)-1)]
x=pd.Series([12,3,4,5,6])
lag1(x)
Out[65]: 6
dat.shape
Out[70]: (247619, 33)
d2=dat.groupby('PATID_CD').agg(lag1)
Traceback (most recent call last):
File "<ipython-input-71-f514757a3da8>", line 1, in <module>
d2=dat.groupby('PATID_CD').agg(lag1)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 4658, in aggregate
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 4109, in aggregate
result = self._aggregate_generic(arg, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 4133, in _aggregate_generic
return self._aggregate_item_by_item(func, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 4162, in _aggregate_item_by_item
colg.aggregate(func, *args, **kwargs), data)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 3497, in aggregate
result = self._aggregate_named(func_or_funcs, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 3627, in _aggregate_named
output = func(group, *args, **kwargs)
File "<ipython-input-64-be977293b7b9>", line 2, in lag1
return x[(len(x)-1)]
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\series.py", line 766, in __getitem__
result = self.index.get_value(self, key)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3103, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\_libs\index.pyx", line 106, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 114, in pandas._libs.index.IndexEngine.get_value
File "pandas\_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 958, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 964, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 23
I don'tknow why my function not working, it gives me a keyerror which suggests the name does not exist. this is a little bit confusing. Am I doing the correct way, or there might be the other solution?
dat.groupby('PATID_CD').agg('mean')
Out[73]:
MONTH_LOOKBACK_NR CCYYMM_CD ... ENG_SPOKEN EVENT_FL
PATID_CD ...
584 12.0 201556.500000 ... 1.0 0.0
4277 12.0 201556.500000 ... 1.0 0.0
I also tried:
dat.groupby('PATID_CD').agg(lambda x : x.iloc[-1,:])
This one is good, but I cannot put this function into a list that compute with the other functions:
def lag1(x):
return x.iloc[-1,:]
d2=dat.groupby(dat['PATID_CD']).agg({'mean','max','min','std','skew', lambda x:len(x),kurtosis,lag1})
Traceback (most recent call last):
File "<ipython-input-86-ac95a8297b5c>", line 1, in <module>
d2=dat.groupby(dat['PATID_CD']).agg({'mean','max','min','std','skew', lambda x:len(x),kurtosis,lag1})
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 4658, in aggregate
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 4089, in aggregate
result, how = self._aggregate(arg, _level=_level, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\base.py", line 551, in _aggregate
_axis=_axis), None
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\base.py", line 596, in _aggregate_multiple_funcs
results.append(colg.aggregate(arg))
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 3485, in aggregate
(_level or 0) + 1)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 3558, in _aggregate_multiple_funcs
results[name] = obj.aggregate(func)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 3497, in aggregate
result = self._aggregate_named(func_or_funcs, *args, **kwargs)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 3627, in _aggregate_named
output = func(group, *args, **kwargs)
File "<ipython-input-85-6bbffa1ca952>", line 2, in lag1
return x.iloc[-1,:]
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 1472, in __getitem__
return self._getitem_tuple(key)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 2013, in _getitem_tuple
self._has_valid_tuple(tup)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 220, in _has_valid_tuple
raise IndexingError('Too many indexers')
IndexingError: Too many indexers
The same as this one:
x=pd.Series([12,3,4,5,6])
lag1(x)
Traceback (most recent call last):
File "<ipython-input-85-6bbffa1ca952>", line 5, in <module>
lag1(x)
File "<ipython-input-85-6bbffa1ca952>", line 2, in lag1
return x.iloc[-1,:]
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 1472, in __getitem__
return self._getitem_tuple(key)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 2013, in _getitem_tuple
self._has_valid_tuple(tup)
File "D:\Users\shan xu\Anaconda3\lib\site-packages\pandas\core\indexing.py", line 220, in _has_valid_tuple
raise IndexingError('Too many indexers')
IndexingError: Too many indexers

You haven't explained what you are trying to accomplish and it is not clear from your code. I don't have enough rep here to add this as a comment so consider:
1) Your first example is performed on a Series that implicitly uses a RangeIndex, so x[(5-1)] == 6. Your second example appears to be a DataFrame for which PATID_CD is the index. If PATID_CD.dtype is e.g. object, you will get a KeyError exception simply because you have passed the wrong argument type (an int) into a pandas indexing expression DataFrame[label] docs.
2) If you simply want to extract the last row of a group, write your groupby call something like
dat.groupby('PATID_CD').apply(lambda x: x.iloc[-1, :])

Related

how to fix External ID not found in the system on user create button?

I'm pretty new in Odoo, for the moment I dind't modified any code but this error is persistent when I try to create a new product.
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/tools/cache.py", line 85, in lookup
r = d[key]
File "/opt/odoo/odoo/odoo/tools/func.py", line 71, in wrapper
return func(self, *args, **kwargs)
File "/opt/odoo/odoo/odoo/tools/lru.py", line 34, in __getitem__
a = self.d[obj]
KeyError: ('product.template', <function ProductTemplate._get_default_category_id at 0x7f77854ab490>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/tools/cache.py", line 85, in lookup
r = d[key]
File "/opt/odoo/odoo/odoo/tools/func.py", line 71, in wrapper
return func(self, *args, **kwargs)
File "/opt/odoo/odoo/odoo/tools/lru.py", line 34, in __getitem__
a = self.d[obj]
KeyError: ('ir.model.data', <function IrModelData._xmlid_lookup at 0x7f778a47b1c0>, 'product.product_category_all')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/opt/odoo/odoo/odoo/http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/odoo/odoo/http.py", line 359, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo/odoo/http.py", line 348, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/odoo/odoo/odoo/http.py", line 916, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo/odoo/http.py", line 535, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1347, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1339, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/opt/odoo/odoo/odoo/api.py", line 464, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/opt/odoo/odoo/odoo/api.py", line 451, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/opt/odoo/odoo/odoo/models.py", line 6356, in onchange
defaults = self.default_get(missing_names)
File "/opt/odoo/odoo/odoo/models.py", line 1410, in default_get
defaults[name] = field.default(self)
File "<decorator-gen-151>", line 2, in _get_default_category_id
File "/opt/odoo/odoo/odoo/tools/cache.py", line 90, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/opt/odoo/odoo/addons/product/models/product_template.py", line 24, in _get_default_category_id
return self.env.ref('product.product_category_all')
File "/opt/odoo/odoo/odoo/api.py", line 578, in ref
res_model, res_id = self['ir.model.data']._xmlid_to_res_model_res_id(
File "/opt/odoo/odoo/odoo/addons/base/models/ir_model.py", line 1935, in _xmlid_to_res_model_res_id
return self._xmlid_lookup(xmlid)[1:3]
File "<decorator-gen-35>", line 2, in _xmlid_lookup
File "/opt/odoo/odoo/odoo/tools/cache.py", line 90, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/opt/odoo/odoo/odoo/addons/base/models/ir_model.py", line 1928, in _xmlid_lookup
raise ValueError('External ID not found in the system: %s' % xmlid)
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/odoo/odoo/odoo/http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo/odoo/http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: External ID not found in the system: product.product_category_all
A little of backstory, I imported a lot of products, atributes and categories and did some testing deleting and importing again that is probably the origin of the issue.
The external ID product.product_category_all should be one of the default product categories introduced/installed by the app/module "product".
Obviously Odoo is using this one as a default value and you get an error, because it was deleted.
The easiest fix is to just update the app/module "product". Odoo will recreate the category and the error should be gone.

TypeError: 'bool' object is not subscriptable in Python3,odoo

I don't know where my problem is. Because years is char field must be string not bool.
I feel really frustrated. What can I do to fix this problem?
Any sort of help will be much appreciated!
Please give me some suggestions. Thanks!
Here is my code:
class HreDetailList(models.EcoModel):
_name = "hre.detail.list"
def _compute_holiday_flag(self):
for record in self:
record.work_on_holiday = False
now_year = int(record.years[:4])
next_year = now_year + 1
holiday_obj = self.env['hra.holiday']
holiday_data = holiday_obj.search([('holi_yy', 'ilike', next_year),
('holi_name', '=', 'Xmas')])
change_obj = self.env['hre.changedtl']
change_data = change_obj.search([('hre_empbas_id.emp_no', '=', record.emp_no),
('trans_flag', '=', True),
('lt_startdate', '=like', record.years[:4] + '%')])
for change_datadtl in change_data:
if change_datadtl.chg_kind == '6M' or change_datadtl.chg_kind == '6N' or change_datadtl.chg_kind == '6L':
if holiday_data.holi_date >= change_datadtl.lt_startdate and holiday_data.holi_date <= change_datadtl.lt_enddate:
record.work_on_holiday = True
break
else:
record.work_on_holiday = False
years = fields.Char(string='Year', size=7, required=True)
work_on_holiday = fields.Boolean(compute=_compute_holiday_flag, string='Work on holiday')
I am getting following error: TypeError: 'bool' object is not subscriptable:
Odoo Server Error
Traceback (most recent call last):
File "/vagrant/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/vagrant/odoo/odoo/http.py", line 682, in dispatch
result = self._call_function(**self.params)
File "/vagrant/odoo/odoo/http.py", line 358, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/vagrant/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/vagrant/odoo/odoo/http.py", line 346, in checked_call
result = self.endpoint(*a, **kw)
File "/vagrant/odoo/odoo/http.py", line 911, in __call__
return self.method(*args, **kw)
File "/vagrant/odoo/odoo/http.py", line 530, in response_wrap
response = f(*args, **kw)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1359, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1351, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 396, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 383, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/vagrant/odoo/odoo/models.py", line 6165, in onchange
value = record[name]
File "/vagrant/odoo/odoo/models.py", line 5640, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/vagrant/odoo/odoo/fields.py", line 972, in __get__
self.compute_value(recs)
File "/vagrant/odoo/odoo/fields.py", line 1111, in compute_value
records._compute_field_value(self)
File "/vagrant/odoo/odoo/models.py", line 4037, in _compute_field_value
field.compute(self)
File "/vagrant/odoo/addons/hre_formwork/models/hre_formwork.py", line 3887, in_compute_holiday_flag
now_year = int(record.years[:4])
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/vagrant/odoo/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/vagrant/odoo/odoo/http.py", line 314, in _handle_exception
raise exception.with_traceback(None) from new_cause
TypeError: 'bool' object is not subscriptable

sequence item 0: expected str instance, int found

I am trying to apply weights of evidence transformation to my data. I am trying to bin my data with the sc.woebin command, however, this: "sequence item 0: expected str instance, int found" error keeps on showing up. I have no clue as to what i could be doing wrong?
I have no clue as to why is it not working.I have tried different server, switching it up a bit, but i don't know what exactly is the problem and what exactly the error means in my case.
bins = sc.woebin(train, y = 'BAD',
min_perc_fine_bin=0.02,
min_perc_coarse_bin=0.05,
stop_limit=0.1,
max_num_bin=8,
method='tree')
The expected result should be of it just processing the data. However, following is the actual result.
"""
"""
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.6/multiprocessing/pool.py", line 47, in starmapstar
return list(itertools.starmap(args[0], args[1]))
File "/usr/local/lib/python3.6/dist-packages/scorecardpy/woebin.py", line 702, in woebin2
stop_limit=stop_limit, max_num_bin=max_num_bin, breaks=breaks, spl_val=spl_val)
File "/usr/local/lib/python3.6/dist-packages/scorecardpy/woebin.py", line 486, in woebin2_tree
binning_tree = woebin2_tree_add_1brkp(dtm, initial_binning, min_perc_coarse_bin, bestbreaks)
File "/usr/local/lib/python3.6/dist-packages/scorecardpy/woebin.py", line 446, in woebin2_tree_add_1brkp
bin_add_1bst = binning_add_1bst(initial_binning, bestbreaks)
File "/usr/local/lib/python3.6/dist-packages/scorecardpy/woebin.py", line 423, in binning_add_1bst
.agg({'good':sum, 'bad':sum, 'bin':lambda x:'%,%'.join(x)}).reset_index()\
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/generic.py", line 1315, in aggregate
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/generic.py", line 186, in aggregate
result, how = self._aggregate(arg, _level=_level, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/base.py", line 498, in _aggregate
result = _agg(arg, _agg_1dim)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/base.py", line 449, in _agg
result[fname] = func(fname, agg_how)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/base.py", line 432, in _agg_1dim
return colg.aggregate(how, _level=(_level or 0) + 1)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/generic.py", line 773, in aggregate
return self._python_agg_general(func_or_funcs, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/groupby.py", line 856, in _python_agg_general
return self._python_apply_general(f)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/groupby.py", line 707, in _python_apply_general
self.axis)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/ops.py", line 190, in apply
res = f(group)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/groupby.py", line 844, in <lambda>
f = lambda x: func(x, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/scorecardpy/woebin.py", line 423, in <lambda>
.agg({'good':sum, 'bad':sum, 'bin':lambda x:'%,%'.join(x)}).reset_index()\
TypeError: sequence item 0: expected str instance, int found
"""
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-209-aa1b22b28748> in <module>()
4 stop_limit=0.1,
5 max_num_bin=10,
----> 6 method='tree')
2 frames
/usr/lib/python3.6/multiprocessing/pool.py in get(self, timeout)
642 return self._value
643 else:
--> 644 raise self._value
645
646 def _set(self, i, obj):
TypeError: sequence item 0: expected str instance, int found
EDIT: This is what my train looks like:
1

TypeError in Dask dataframe while converting to pandas using compute()

I can't figure out what is the problem in the given code:
I am using dask to merge several dataframes. After merging I want to find the unique values from one of the column. I am getting type error while converting from dask to pandas using unique().compute(). But, I cannot seem to find what actually is the problem. It says that str cannot be assigned as int but, in some of the files the code passses through and in some it doesn't. I also cannot find the problem with data structure.
Any suggestions??
import pandas as pd
import dask.dataframe as dd
# Everything is fine until merging
# I have put several print(markers) to find the problem code
print('dask cols')
print(df_by_dask_merged.columns)
print()
print(dask_cols)
print()
print('find unique contigs values in dask dataframe')
pd_df = df_by_dask_merged['contig']
print(pd_df)
print()
print('mark 02')
# this is the problem code ??
pd_df_contig = pd_df.unique().compute()
print(pd_df_contig)
print('mark 03')
Output on Terminal:
dask cols
Index(['contig', 'pos', 'ref', 'all-alleles', 'ms01e_PI', 'ms01e_PG_al',
'ms02g_PI', 'ms02g_PG_al', 'all-freq'],
dtype='object')
['contig', 'pos', 'ref', 'all-alleles', 'ms01e_PI', 'ms01e_PG_al', 'ms02g_PI', 'ms02g_PG_al', 'all-freq']
find unique contigs values in dask dataframe
Dask Series Structure:
npartitions=1
int64
...
Name: contig, dtype: int64
Dask Name: getitem, 52 tasks
mark 02
Traceback (most recent call last):
File "/home/everestial007/.local/lib/python3.5/site-packages/pandas/indexes/base.py", line 2145, in get_value
return tslib.get_value_box(s, key)
File "pandas/tslib.pyx", line 880, in pandas.tslib.get_value_box (pandas/tslib.c:17368)
File "pandas/tslib.pyx", line 889, in pandas.tslib.get_value_box (pandas/tslib.c:17042)
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "merge_haplotype.py", line 305, in <module>
main()
File "merge_haplotype.py", line 152, in main
pd_df_contig = pd_df.unique().compute()
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/base.py", line 155, in compute
(result,) = compute(self, traverse=False, **kwargs)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/base.py", line 404, in compute
results = get(dsk, keys, **kwargs)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/threaded.py", line 75, in get
pack_exception=pack_exception, **kwargs)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/local.py", line 521, in get_async
raise_exception(exc, tb)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/compatibility.py", line 67, in reraise
raise exc
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/local.py", line 290, in execute_task
result = _execute_task(task, data)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/local.py", line 271, in _execute_task
return func(*args2)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/dataframe/core.py", line 3404, in apply_and_enforce
df = func(*args, **kwargs)
File "/home/everestial007/anaconda3/lib/python3.5/site-packages/dask/utils.py", line 687, in __call__
return getattr(obj, self.method)(*args, **kwargs)
File "/home/everestial007/.local/lib/python3.5/site-packages/pandas/core/frame.py", line 4133, in apply
return self._apply_standard(f, axis, reduce=reduce)
File "/home/everestial007/.local/lib/python3.5/site-packages/pandas/core/frame.py", line 4229, in _apply_standard
results[i] = func(v)
File "merge_haplotype.py", line 249, in <lambda>
apply(lambda row : update_cols(row, sample_name), axis=1, meta=(int))
File "merge_haplotype.py", line 278, in update_cols
if 'N|N' in df_by_dask[sample_name + '_PG_al']:
File "/home/everestial007/.local/lib/python3.5/site-packages/pandas/core/series.py", line 601, in __getitem__
result = self.index.get_value(self, key)
File "/home/everestial007/.local/lib/python3.5/site-packages/pandas/indexes/base.py", line 2153, in get_value
raise e1
File "/home/everestial007/.local/lib/python3.5/site-packages/pandas/indexes/base.py", line 2139, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas/index.pyx", line 105, in pandas.index.IndexEngine.get_value (pandas/index.c:3338)
File "pandas/index.pyx", line 113, in pandas.index.IndexEngine.get_value (pandas/index.c:3041)
File "pandas/index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas/index.c:4024)
File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13161)
File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13115)
KeyError: ('ms02g_PG_al', 'occurred at index 0')

odoo 9 AssertionError assert self in records and field in fs

while I am trying to update value that affect computed field I got this error:
Odoo Server Error
Traceback (most recent call last):
File "/Users/abdalla/projects/greenway/odoo-server/openerp/http.py", line 647, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/http.py", line 684, in dispatch
result = self._call_function(**self.params)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/http.py", line 320, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/http.py", line 313, in checked_call
result = self.endpoint(*a, **kw)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/http.py", line 963, in call
return self.method(*args, **kw)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/http.py", line 513, in response_wrap
response = f(*args, **kw)
File "/Users/abdalla/projects/greenway/odoo-server/addons/web/controllers/main.py", line 904, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/addons/web/controllers/main.py", line 896, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/api.py", line 381, in old_api
result = method(recs, *args, **kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/models.py", line 6036, in onchange
record.mapped(field_seq)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/models.py", line 5534, in mapped
recs = recs._mapped_func(operator.itemgetter(name))
File "/Users/abdalla/projects/greenway/odoo-server/openerp/models.py", line 5514, in _mapped_func
vals = [func(rec) for rec in self]
File "/Users/abdalla/projects/greenway/odoo-server/openerp/models.py", line 5752, in getitem
return self._fields[key].get(self, type(self))
File "/Users/abdalla/projects/greenway/odoo-server/openerp/fields.py", line 829, in get
self.determine_value(record)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/fields.py", line 927, in determine_value
record._prefetch_field(self)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/Users/abdalla/projects/greenway/odoo-server/openerp/models.py", line 3295, in _prefetch_field
assert self in records and field in fs
AssertionError
finally I found the problem:
the problem is that the method of the computed field is not exist (I renamed it accidentally). so when odoo try to get the value of this field it failed, and show this strange error

Categories