2013-10-09 5 views
2

에와, 나는 다음과 같은 발생 그 위에팬더 HDF5 선택은 어디 비 자연라는 이름의 열 이국적인 팬더/HDF5 문제의 내 계속 마구에

fact_hdf.select('store_0_0', columns=['o', 'a-6', 'm-13']) 

하지만, 내 선택 문이하는 가을 : 일반적으로 문제를 제공하지 않습니다 음수 인 "시스템"IDS 등), 좋은 이유,

>>> fact_hdf.select('store_0_0', columns=['o', 'a-6', 'm-13'], where=[('a-6', '=', [0, 25, 28])]) 
blablabla 
File "/srv/www/li/venv/local/lib/python2.7/site-packages/tables/table.py", line 1251, in _required_expr_vars 
    raise NameError("name ``%s`` is not defined" % var) 
NameError: name ``a`` is not defined 

가 있는가 그걸 해결할 방법이 있니? 내 부정적인 값을 "a-1"에서 "a_1"로 바꿀 수는 있지만 시스템에서 모든 데이터를 다시로드한다는 의미입니다. 어느 정도입니다! :)

제안을 환영합니다!

답변

2

여기에 아주 방법이있는 테스트 테이블

In [1]: df = DataFrame({ 'a-6' : [1,2,3,np.nan] }) 

In [2]: df 
Out[2]: 
    a-6 
0 1 
1 2 
2 3 
3 NaN 

In [3]: df.to_hdf('test.h5','df',mode='w',table=True) 

In [5]: df.to_hdf('test.h5','df',mode='w',table=True,data_columns=True) 
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'a-6'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though 
    NaturalNameWarning) 
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'a-6_kind'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though 
    NaturalNameWarning) 
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'a-6_dtype'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though 
    NaturalNameWarning) 

하지만 코드 자체에이를 구축하는 것. 다음과 같이 열 이름에 대한 변수 대체를 수행 할 수 있습니다. 이

(Pdb) self.table.table.readWhere("(x>2.0)", 
     condvars={ 'x' : getattr(self.table.table.cols,'a-6')}) 
array([(2, 3.0)], 
     dtype=[('index', '<i8'), ('a-6', '<f8')]) 

예를 들어,을 대신하는 경우 여기에 (마스터)에 기존 루틴

def select(self): 
     """ 
     generate the selection 
     """ 
     if self.condition is not None: 
      return self.table.table.readWhere(self.condition.format(), start=self.start, stop=self.stop) 
     elif self.coordinates is not None: 
      return self.table.table.readCoordinates(self.coordinates) 
     return self.table.table.read(start=self.start, stop=self.stop) 

입니다 x을 열 참조와 연결하면 데이터를 가져올 수 있습니다.

잘못된 열 이름을 검색하면이 작업을 수행 할 수 있지만 매우 까다 롭습니다.

불행히도 열의 이름을 바꾸는 것이 좋습니다.

+0

다시 한번 감사드립니다. Jeff! 나는 그것이 0.10/0.11과 0.12 사이에서 바뀌 었는지 궁금하다. 그러나 절박한 0.13의 새로운 어디에서 clausule이든 상관 없다고 생각한다. :) 경고를 위해 팬더 HDF5 문서에 넣는 것이 좋은 아이디어 일 것이다. 신규 사용자? 판다 자체는 실제로 문제가없고 정상적인 데이터 검색 작업을 수행하기 때문에 선택 진술 문제가 발생할 때까지는 분명하지 않습니다. – Carst

+0

옙 ... 나는 그렇게 할 것입니다. 팬더 버전은별로 중요하지 않습니다. (0.13에서는 허용되는 구문이 실제로 더 까다로울 수 있기 때문에 훨씬 더 유연합니다.) [here] (http://pandas.pydata.org/pandas-docs/ dev/whatsnew.html # hdfstore-api-changes) – Jeff