Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行FSRS4Anki v3.5.0 Optimizer的1.2步骤时出现"KeyError"[BUG] #78

Closed
5mdld opened this issue Oct 18, 2022 · 5 comments · Fixed by #79
Closed

执行FSRS4Anki v3.5.0 Optimizer的1.2步骤时出现"KeyError"[BUG] #78

5mdld opened this issue Oct 18, 2022 · 5 comments · Fixed by #79
Labels
bug Something isn't working

Comments

@5mdld
Copy link

5mdld commented Oct 18, 2022

Describe the bug
使用Anki v2.1.55 beta 2导出的.apkg文件(已经勾选了兼容旧版本),
执行FSRS4Anki v3.5.0 Optimizer的1.2步骤时出现"KeyError"
如有需要,可以邮件发您使用的.apkg文件

KeyError Traceback (most recent call last)
in
66 return group
67
---> 68 df = df.groupby(by=['r_history', 'delta_t']).progress_apply(cal_retention)
69 print("Retention calculated.")
70 df = df.drop(columns=['id', 'cid', 'usn', 'ivl', 'last_lvl', 'factor', 'time', 'type', 'create_date', 'review_date', 'real_days', 'r', 't_history'])

9 frames
/usr/local/lib/python3.7/dist-packages/tqdm/std.py in inner(df, func, *args, **kwargs)
812 # on the df using our wrapper (which provides bar updating)
813 try:
--> 814 return getattr(df, df_function)(wrapper, **kwargs)
815 finally:
816 t.close()

/usr/local/lib/python3.7/dist-packages/pandas/core/groupby/groupby.py in apply(self, func, *args, **kwargs)
1273 with option_context("mode.chained_assignment", None):
1274 try:
-> 1275 result = self._python_apply_general(f, self._selected_obj)
1276 except TypeError:
1277 # gh-20949

/usr/local/lib/python3.7/dist-packages/pandas/core/groupby/groupby.py in _python_apply_general(self, f, data)
1307 data after applying f
1308 """
-> 1309 keys, values, mutated = self.grouper.apply(f, data, self.axis)
1310
1311 return self._wrap_applied_output(

/usr/local/lib/python3.7/dist-packages/pandas/core/groupby/ops.py in apply(self, f, data, axis)
850 # group might be modified
851 group_axes = group.axes
--> 852 res = f(group)
853 if not _is_indexed_like(res, group_axes, axis):
854 mutated = True

/usr/local/lib/python3.7/dist-packages/tqdm/std.py in wrapper(*args, **kwargs)
807 # take a fast or slow code path; so stop when t.total==t.n
808 t.update(n=1 if not t.total or t.n < t.total else 0)
--> 809 return func(*args, **kwargs)
810
811 # Apply the provided function (in **kwargs)

in cal_retention(group)
62
63 def cal_retention(group: pd.DataFrame) -> pd.DataFrame:
---> 64 group['retention'] = round(group['r'].map(lambda x: {1: 0, 2: 1, 3: 1, 4: 1}[x]).mean(), 4)
65 group['total_cnt'] = group.shape[0]
66 return group

/usr/local/lib/python3.7/dist-packages/pandas/core/series.py in map(self, arg, na_action)
4159 dtype: object
4160 """
-> 4161 new_values = super()._map_values(arg, na_action=na_action)
4162 return self._constructor(new_values, index=self.index).finalize(
4163 self, method="map"

/usr/local/lib/python3.7/dist-packages/pandas/core/base.py in _map_values(self, mapper, na_action)
868
869 # mapper is a function
--> 870 new_values = map_f(values, mapper)
871
872 return new_values

/usr/local/lib/python3.7/dist-packages/pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

in (x)
62
63 def cal_retention(group: pd.DataFrame) -> pd.DataFrame:
---> 64 group['retention'] = round(group['r'].map(lambda x: {1: 0, 2: 1, 3: 1, 4: 1}[x]).mean(), 4)
65 group['total_cnt'] = group.shape[0]
66 return group

KeyError: 0

Environment

  • Anki version: [2.1.55 beta 2]
  • OS: [macOS 13 beta (22A5373b)]
@5mdld 5mdld added the bug Something isn't working label Oct 18, 2022
@5mdld
Copy link
Author

5mdld commented Oct 18, 2022

感觉好像文件太大就会出现该问题?选取了部分卡(两千个左右)打包执行的时候一切正常

@L-M-Sherlock
Copy link
Member

看起来是异常数据,理论上反馈只有 1 2 3 4 四种,我会在下个版本修复。

@5mdld
Copy link
Author

5mdld commented Oct 18, 2022

谢谢,等待修复

@5mdld 5mdld closed this as completed Oct 18, 2022
@L-M-Sherlock L-M-Sherlock linked a pull request Oct 18, 2022 that will close this issue
@L-M-Sherlock
Copy link
Member

@5mdld
Copy link
Author

5mdld commented Oct 18, 2022

谢谢,已可以正常使用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants