cannot use trace routines with Pandas · Issue #1547 · pandas-dev/pandas (original) (raw)

Because of the way local variables are used in read_cvs, setting a tracing routine will fail at that point. Here is a test case with an arbitrarily simple tracing routine:

def trace_memory_usage(frame, event, arg):
    return trace_memory_usage

import sys
sys.settrace(trace_memory_usage)

if __name__ == '__main__':
    from pandas.io.parsers import read_csv
    print read_csv('dummy.txt')

this fails with a traceback

Traceback (most recent call last):
  File "test2.py", line 10, in <module>
    print read_csv('dummy.txt')
  File "/volatile/fabian/envs/p26/lib/python2.6/site-packages/pandas/io/parsers.py", line 226, in read_csv
    return _read(TextParser, filepath_or_buffer, kwds2)
  File "/volatile/fabian/envs/p26/lib/python2.6/site-packages/pandas/io/parsers.py", line 185, in _read
    parser = cls(f, **kwds)
TypeError: __init__() got an unexpected keyword argument 'sep'

Some real-world utilities that are affected because of this are profile (but not cProfile) and memory_profiler.