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

fetch对列表数据无效 #39

Closed
fastpx2014 opened this issue Feb 28, 2022 · 1 comment
Closed

fetch对列表数据无效 #39

fastpx2014 opened this issue Feb 28, 2022 · 1 comment
Assignees
Labels
bug Something isn't working v3.5.x Version 3.5 Serials

Comments

@fastpx2014
Copy link
Collaborator

代码示例

from borax.datasets.fetch import fetch

points =  [
    ['a', 1, 3],
    ['b', 2, 4]
]

names, xs = fetch(points, 0, 1) # 预期 ['a', 'b'], [1,2]
names, xs = fetch(points, 0, 1, getter=lambda item, key: item[key])

代码执行错误

  File "E:\projects\demo.py", line 8, in fujian_area_bar
    names, xs = fetch(points, 0, 1)
  File "D:\py\lib\site-packages\borax\datasets\fetch.py", line 72, in fetch
    return list(ifetch(iterable, key, *keys, default=default, defaults=defaults, getter=getter))
  File "D:\py\lib\site-packages\borax\datasets\fetch.py", line 44, in _getter
    return partial(bget, key=key, default=default)(item)
  File "D:\py\lib\site-packages\borax\datasets\fetch.py", line 20, in bget
    return getattr(obj, key)
TypeError: getattr(): attribute name must be string
@fastpx2014 fastpx2014 added bug Something isn't working v3.5.x Version 3.5 Serials labels Feb 28, 2022
@fastpx2014 fastpx2014 self-assigned this Feb 28, 2022
@fastpx2014
Copy link
Collaborator Author

    try:
        return obj[key]
    except KeyError:
        pass

该段代码无法处理 TypeError

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

No branches or pull requests

2 participants