【问题标题】:Pytables slow on query for non-matching stringPytables 查询不匹配的字符串很慢
【发布时间】:2014-10-12 17:09:12
【问题描述】:

我在 python 方面相对较新,我正在使用 pytables 将一些基因组注释存储在 hdf 中以便更快地查询。我发现查询表中不匹配的字符串很慢,但我不确定如何优化它以获得更好的性能。

下面显示的是其中一张表:

In [5]: t
Out[5]: 
/gene/annotation (Table(315202,), fletcher32, blosc(5)) ''
  description := {
  "name": StringCol(itemsize=36, shape=(), dflt='', pos=0),
  "track": StringCol(itemsize=12, shape=(), dflt='', pos=1),
  "etype": StringCol(itemsize=12, shape=(), dflt='', pos=2),
  "event": StringCol(itemsize=36, shape=(), dflt='', pos=3)}
  byteorder := 'irrelevant'
  chunkshape := (1365,)
  autoindex := True
  colindexes := {
    "name": Index(9, full, shuffle, zlib(1)).is_csi=True}

当条件匹配表中的某些内容时,timeit 以微秒为单位返回。

In [6]: timeit [x for x in t.where("name == 'record_exists_in_table'")]
10000 loops, best of 3: 109 µs per loop

但是,当我尝试搜索一个不存在的字符串时,它是以毫秒为单位的。

In [8]: timeit [x for x in t.where("name == 'no_such_record'")]
10 loops, best of 3: 56 ms per loop

任何能指引我走向正确方向的建议将不胜感激!

【问题讨论】:

  • 嗯,这很有趣。你能在 PyTables github repo 中提交一张票吗?如果您可以添加一个独立的示例,那就太好了。我想看看那个。
  • 以防万一你的问题和我的一样:stackoverflow.com/questions/26197622/…
  • @Francesc 我可以在 3.1.1 中确认这种回归。降级到 3.0.0 解决了这个问题。带有要重现的代码的相应 github 问题的链接是:github.com/PyTables/PyTables/issues/390

标签: python pytables


【解决方案1】:

我已经在网络上用尽了我的搜索,但还没有找到任何可以解决问题的方法。所以我决定在 biopython 中使用SeqIO.index_db() 创建一个单独的索引,然后在执行 pytable 查询之前检查以确保找到条件。不完全是我正在寻找的漂亮解决方案,但这会做。它大大提高了非匹配条件下的性能。

In [6]: timeit [x for x in t.where("name == 'not_found_in_table'")]
10 loops, best of 3: 51.6 ms per loop

In [9]: timeit [x for x in t.search_by_gene('not_found_in_table')]
10000 loops, best of 3: 29.5 µs per loop

【讨论】:

    猜你喜欢
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 2014-07-21
    相关资源
    最近更新 更多