
연산되는 방식
python의 모든 연산자는 특수메서드로 구현되어있다.
따라서 p in z라는 구문을 실행했을 때 __contains__라는 특수메서드가 호출되게 된다.
pandas 구현
아래의 특수메서드가 호출된다 이때 key in self._info_axis연산을 하게 되는데
# pandas.core.generic.py > NDFrame > __contains__
@final
def __contains__(self, key) -> bool_t:
"""True if the key is in the info axis"""
return key in self._info_axis
따라서 아래와 같은 방식으로 Index의 값과 비교해야지 True를 반환한다.
* 추가적으로 @final 데코레이터는 상속 및 재정의 사용을 제한하는 데 사용됨
>>> self._info_axis
RangeIndex(start=0, stop=1, step=1)
>>> 0 == self._info_axis
array([ True])
Reference
https://peps.python.org/pep-0591/
https://www.facebook.com/groups/codingeverybody/posts/8913007015406422/?comment_id=8913183225388801
