class InfiniteFrame(UserFrame):
counts = {}
log = []
def __getitem__(self, name):
InfiniteFrame.log.append(name)
count = InfiniteFrame.counts.setdefault(name, 0)
count += 1
InfiniteFrame.counts[name] = count
# if not for this count check, we'd go into an infinite loop
if count > 5:
raise AttributeError('error through exaustion')
return self.ix[:2]
idf = InfiniteFrame(np.random.randn(10, 10))
cols = idf.columns
counts = InfiniteFrame.counts
print counts
# {'columns': 1, 'ix': 6}
print InfiniteFrame.log
# ['columns', 'ix', 'ix', 'ix', 'ix', 'ix', 'ix']
Due to the DataSet changes that were merged in __tr_getattr__ calls __getitem__ which can run into an infinite loop with subclasses that override __getitem__.
If it weren't for the explicit loop check, this would run infinitely. If the overridding __getitem__ doesn't properly raise AttributeError for things like ix then this will run infinitely. Even though it the __getitem__ would have worked if the getattr -> getitem logic wasn't there.
Due to the DataSet changes that were merged in
__tr_getattr__
calls__getitem__
which can run into an infinite loop with subclasses that override__getitem__
.If it weren't for the explicit loop check, this would run infinitely. If the overridding
__getitem__
doesn't properly raise AttributeError for things likeix
then this will run infinitely. Even though it the__getitem__
would have worked if the getattr -> getitem logic wasn't there.