%lprun 无法在 jupyter notebook 中得到结果

%lprun could not get result in jupyternotebook

代码:

def combCreate(grp,num):
    d = chain(*(map(lambda x: (combinations(x,num)),grp)))
    return set(d)

# Comb DataFrame abt Freq & occured date
def combFrame(grp):
    arr = df.loc[:,'date':'6th'].values
    t = []
    cnt = []
    for i in grp:
        tmp_cnt = 0
        tmp_time = []
        for v,date in zip(arr[:,1:],arr[:,0]):
            if set(i)<=set(v):
                tmp_time.append(date)
                tmp_cnt=tmp_cnt+1
        t.append(tuple(tmp_time))
        cnt.append(tmp_cnt)
    df_comb = pd.DataFrame({'cnt':cnt,'time':t},index=grp)
    return df_comb

t_arr = df.loc[:,'1st':'6th'].values[:5]
comb_create = combCreate(t_arr,4)
%lprun -f combFrame(comb_create)

当我在 jupyter notebook 中 运行 %lprun 时,除了 UserWarning 什么都看不到。不知道什么意思

/usr/local/lib/python3.6/site-packages/line_profiler.py:321: UserWarning: Could not extract a code object for the object              cnt                                               time
6  15 17 30    5  (2003-03-09 00:00:00, 2003-10-05 00:00:00, 200...
9  19 20 21    2         (2003-02-27 00:00:00, 2011-08-21 00:00:00)
4  20 21 26    2         (2003-02-27 00:00:00, 2011-05-19 00:00:00)
6  7  10 25    1                             (2003-03-06 00:00:00,)
4  6  17 30    3  (2003-03-09 00:00:00, 2011-06-09 00:00:00, 201...
   9  20 21    1                             (2003-02-27 00:00:00,)
10 11 26 28    1                             (2003-02-23 00:00:00,)
7  23 28 32    1                             (2003-03-02 00:00:00,)
4  6  15 30    3  (2003-03-09 00:00:00, 2003-10-02 00:00:00, 200...
      13 25    1                             (2003-03-06 00:00:00,)
      10 25    3  (2003-03-06 00:00:00, 2005-05-22 00:00:00, 200...
11 12 13 28    2         (2003-02-23 00:00:00, 2018-01-28 00:00:00)
7  10 13 25    5  (2003-03-06 00:00:00, 2007-01-09 00:00:00, 200...
4  19 20 21    1                             (2003-02-27 00:00:00,)
1  7  10 28    1                             (2003-03-02 00:00:00,)
         32    3  (2003-03-02 00:00:00, 2004-02-01 00:00:00, 200...
4  15 30 31    3  (2003-03-09 00:00:00, 2006-10-31 00:00:00, 201...
   6  30 31    2         (2003-03-09 00:00:00, 2013-02-07 00:00:00)
11 13 26 28    2         (2003-02-23 00:00:00, 2018-01-28 00:00:00)
10 11 12 28    2         (2003-02-23 00:00:00, 2013-07-11 00:00:00)
7  10 23 28    3  (2003-03-02 00:00:00, 2017-08-06 00:00:00, 201...
4  9  20 26    2         (2003-02-27 00:00:00, 2007-01-02 00:00:00)
7  10 28 32    1                             (2003-03-02 00:00:00,)
4  7  13 25    2         (2003-03-06 00:00:00, 2010-03-07 00:00:00)
1  7  28 32    2         (2003-03-02 00:00:00, 2015-12-08 00:00:00)
10 11 12 26    4  (2003-02-23 00:00:00, 2008-10-23 00:00:00, 201...
6  17 30 31    2         (2003-03-09 00:00:00, 2004-11-30 00:00:00)
4  6  7  13    1                             (2003-03-06 00:00:00,)
1  7  23 28    3  (2003-03-02 00:00:00, 2005-01-02 00:00:00, 201...
19 20 21 26    4  (2003-02-27 00:00:00, 2005-03-31 00:00:00, 200...
10 12 13 26    4  (2003-02-23 00:00:00, 2011-08-25 00:00:00, 201...
4  7  10 25    3  (2003-03-06 00:00:00, 2010-03-07 00:00:00, 201...
11 12 26 28    2         (2003-02-23 00:00:00, 2018-01-28 00:00:00)
1  7  23 32    1                             (2003-03-02 00:00:00,)
4  6  15 31    1                             (2003-03-09 00:00:00,)
      17 31    2         (2003-03-09 00:00:00, 2007-12-02 00:00:00)
   15 17 31    2         (2003-03-09 00:00:00, 2006-12-14 00:00:00)
   9  21 26    4  (2003-02-27 00:00:00, 2009-02-05 00:00:00, 201...
6  15 30 31    2         (2003-03-09 00:00:00, 2005-05-19 00:00:00)
10 12 13 28    1                             (2003-02-23 00:00:00,)
4  9  19 21    1                             (2003-02-27 00:00:00,)
10 11 13 26    1                             (2003-02-23 00:00:00,)
4  6  7  25    4  (2003-03-06 00:00:00, 2007-07-08 00:00:00, 201...
   7  10 13    2         (2003-03-06 00:00:00, 2010-03-07 00:00:00)
1  10 23 28    2         (2003-03-02 00:00:00, 2016-01-07 00:00:00)
      28 32    1                             (2003-03-02 00:00:00,)
9  20 21 26    2         (2003-02-27 00:00:00, 2011-08-21 00:00:00)
6  7  13 25    2         (2003-03-06 00:00:00, 2003-08-10 00:00:00)
4  10 13 25    4  (2003-03-06 00:00:00, 2007-11-15 00:00:00, 201...
   17 30 31    1                             (2003-03-09 00:00:00,)
   9  19 26    1                             (2003-02-27 00:00:00,)
10 13 26 28    2         (2003-02-23 00:00:00, 2006-11-14 00:00:00)
6  7  10 13    1                             (2003-03-06 00:00:00,)
4  19 20 26    2         (2003-02-27 00:00:00, 2016-03-29 00:00:00)
15 17 30 31    1                             (2003-03-09 00:00:00,)
4  6  7  10    2         (2003-03-06 00:00:00, 2014-03-02 00:00:00)
6  15 17 31    2         (2003-03-09 00:00:00, 2015-02-05 00:00:00)
10 11 12 13    1                             (2003-02-23 00:00:00,)
7  10 23 32    1                             (2003-03-02 00:00:00,)
4  6  10 13    2         (2003-03-06 00:00:00, 2011-01-09 00:00:00)
   15 17 30    1                             (2003-03-09 00:00:00,)
12 13 26 28    2         (2003-02-23 00:00:00, 2018-01-28 00:00:00)
4  6  15 17    2         (2003-03-09 00:00:00, 2009-02-10 00:00:00)
9  19 21 26    4  (2003-02-27 00:00:00, 2003-03-16 00:00:00, 201...
11 12 13 26    2         (2003-02-23 00:00:00, 2018-01-28 00:00:00)
4  9  19 20    2         (2003-02-27 00:00:00, 2004-04-29 00:00:00)
   19 21 26    1                             (2003-02-27 00:00:00,)
10 23 28 32    2         (2003-03-02 00:00:00, 2013-07-11 00:00:00)
9  19 20 26    4  (2003-02-27 00:00:00, 2008-02-24 00:00:00, 201...
1  10 23 32    1                             (2003-03-02 00:00:00,)
10 11 13 28    1                             (2003-02-23 00:00:00,)
6  10 13 25    2         (2003-03-06 00:00:00, 2014-07-24 00:00:00)
1  7  10 23    2         (2003-03-02 00:00:00, 2017-04-13 00:00:00)
   23 28 32    2         (2003-03-02 00:00:00, 2007-10-21 00:00:00)
10 12 26 28    2         (2003-02-23 00:00:00, 2008-08-10 00:00:00)
  profile = LineProfiler(*funcs)

希望:

解决并说明原因。

我错过了在 %lprun 之后添加函数名称。正确答案是

 %lprun -f combFrame combFrame(comb_create)

Total time: 0.630435 s
File: <ipython-input-340-ea2ba2ae7d55>
Function: combFrame at line 10

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    10                                           def combFrame(grp):
    11         1      32015.0  32015.0      5.1      arr = df.loc[:,'date':'6th'].values
    12         1          4.0      4.0      0.0      t = []
    13         1          2.0      2.0      0.0      cnt = []
    14        76        420.0      5.5      0.1      for i in grp:
    15        75         59.0      0.8      0.0          tmp_cnt = 0
    16        75         88.0      1.2      0.0          tmp_time = []
    17    170025     157326.0      0.9     25.0          for v,date in zip(arr[:,1:],arr[:,0]):
    18    169950     428583.0      2.5     68.0              if set(i)<=set(v):
    19       155        236.0      1.5      0.0                  tmp_time.append(date)
    20       155        158.0      1.0      0.0                  tmp_cnt=tmp_cnt+1
    21        75        586.0      7.8      0.1          t.append(tuple(tmp_time))
    22        75        107.0      1.4      0.0          cnt.append(tmp_cnt)
    23         1      10849.0  10849.0      1.7      df_comb = pd.DataFrame({'cnt':cnt,'time':t},index=grp)
    24         1          2.0      2.0      0.0      return df_comb