def dip_pval_tabinterpol(dip, N):
    '''
        dip     -   dip value computed from dip_from_cdf
        N       -   number of observations
    '''

    # if qDiptab_df is None:
    #     raise DataError("Tabulated p-values not available. See installation instructions.")

    if np.isnan(N) or N < 10:
        return np.nan

    qDiptab_dict = {'0': {4: 0.125,
      5: 0.1,
      6: 0.0833333333333333,
      7: 0.0714285714285714,
      8: 0.0625,
      9: 0.0555555555555556,
      10: 0.05,
      15: 0.0341378172277919,
      20: 0.033718563622065004,
      30: 0.0262674485075642,
      50: 0.0218544781364545,
      100: 0.0164852597438403,
      200: 0.0111236388849688,
      500: 0.007554885975761959,
      1000: 0.00541658127872122,
      2000: 0.0039043999745055702,
      5000: 0.00245657785440433,
      10000: 0.00174954269199566,
      20000: 0.00119458814106091,
      40000: 0.000852415648011777,
      72000: 0.000644400053256997},
     '0.01': {4: 0.125,
      5: 0.1,
      6: 0.0833333333333333,
      7: 0.0714285714285714,
      8: 0.0625,
      9: 0.0613018090298924,
      10: 0.0610132555623269,
      15: 0.0546284208048975,
      20: 0.0474333740698401,
      30: 0.0395871890405749,
      50: 0.0314400501999916,
      100: 0.022831985803043,
      200: 0.0165017735429825,
      500: 0.0106403461127515,
      1000: 0.0076028674530018705,
      2000: 0.0054166418179658294,
      5000: 0.0034480928223332603,
      10000: 0.00244595133885302,
      20000: 0.00173435346896287,
      40000: 0.00122883479310665,
      72000: 0.000916872204484283},
     '0.02': {4: 0.125,
      5: 0.1,
      6: 0.0833333333333333,
      7: 0.0714285714285714,
      8: 0.0656911994503283,
      9: 0.0658615858179315,
      10: 0.0651627333214016,
      15: 0.0572191260231815,
      20: 0.0490891387627092,
      30: 0.0414574606741673,
      50: 0.0329008160470834,
      100: 0.0238917486442849,
      200: 0.0172594157992489,
      500: 0.0111255573208294,
      1000: 0.00794987834644799,
      2000: 0.0056617138625232296,
      5000: 0.00360473943713036,
      10000: 0.00255710802275612,
      20000: 0.0018119443458468102,
      40000: 0.0012846930445701802,
      72000: 0.0009579329467655321},
     '0.05': {4: 0.125,
      5: 0.1,
      6: 0.0833333333333333,
      7: 0.0725717816250742,
      8: 0.0738651136071762,
      9: 0.0732651142535317,
      10: 0.0718321619656165,
      15: 0.0610087367689692,
      20: 0.052719998201553,
      30: 0.0444462614069956,
      50: 0.0353023819040016,
      100: 0.0256559537977579,
      200: 0.0185259426032926,
      500: 0.0119353655328931,
      1000: 0.0085216518343594,
      2000: 0.00607120971135229,
      5000: 0.0038632654801084897,
      10000: 0.00273990955227265,
      20000: 0.00194259470485893,
      40000: 0.0013761765052555301,
      72000: 0.00102641863872347},
     '0.1': {4: 0.125,
      5: 0.1,
      6: 0.0833333333333333,
      7: 0.0817315478539489,
      8: 0.0820045917762512,
      9: 0.0803941629593475,
      10: 0.077966212182459,
      15: 0.0642657137330444,
      20: 0.0567795509056742,
      30: 0.0473998525042686,
      50: 0.0377279973102482,
      100: 0.0273987414570948,
      200: 0.0197917612637521,
      500: 0.0127411306411808,
      1000: 0.00909775605533253,
      2000: 0.0064762535755248,
      5000: 0.00412089506752692,
      10000: 0.0029225480567908,
      20000: 0.00207173719623868,
      40000: 0.0014675150200632301,
      72000: 0.0010949515421800199},
     '0.2': {4: 0.125,
      5: 0.1,
      6: 0.0924514470941933,
      7: 0.0940590181922527,
      8: 0.0922700601131892,
      9: 0.0890432420913848,
      10: 0.0852835359834564,
      15: 0.0692234107989591,
      20: 0.0620134674468181,
      30: 0.0516677370374349,
      50: 0.0410699984399582,
      100: 0.0298109370830153,
      200: 0.0215233745778454,
      500: 0.0138524542751814,
      1000: 0.00988924521014078,
      2000: 0.00703573098590029,
      5000: 0.00447640050137479,
      10000: 0.00317374638422465,
      20000: 0.00224993202086955,
      40000: 0.00159376453672466,
      72000: 0.00118904090369415},
     '0.3': {4: 0.125,
      5: 0.1,
      6: 0.103913431059949,
      7: 0.10324449080087102,
      8: 0.0996737189599363,
      9: 0.0950811420297928,
      10: 0.0903204173707099,
      15: 0.0745462114365167,
      20: 0.0660163872069048,
      30: 0.0551037519001622,
      50: 0.0437704598622665,
      100: 0.0317771496530253,
      200: 0.0229259769870428,
      500: 0.0147536004288476,
      1000: 0.0105309297090482,
      2000: 0.007494212545892991,
      5000: 0.00476555693102276,
      10000: 0.00338072258533527,
      20000: 0.00239520831473419,
      40000: 0.00169668445506151,
      72000: 0.00126575197699874},
     '0.4': {4: 0.125,
      5: 0.10872059357632902,
      6: 0.113885220640212,
      7: 0.110964599995697,
      8: 0.10573353180273701,
      9: 0.0999380897811046,
      10: 0.0943334983745117,
      15: 0.0792030878981762,
      20: 0.0696506075066401,
      30: 0.058265005347492994,
      50: 0.0462925642671299,
      100: 0.0336073821590387,
      200: 0.024243848341112,
      500: 0.0155963185751048,
      1000: 0.0111322726797384,
      2000: 0.007920878896017329,
      5000: 0.005037040297500721,
      10000: 0.0035724387653598205,
      20000: 0.00253036792824665,
      40000: 0.0017925341833790601,
      72000: 0.00133750966361506},
     '0.5': {4: 0.125,
      5: 0.12156379802641401,
      6: 0.123071187137781,
      7: 0.11780784650433501,
      8: 0.11103512984770501,
      9: 0.10415356007586801,
      10: 0.0977817630384725,
      15: 0.083621033469191,
      20: 0.0733437740592714,
      30: 0.0614510857304343,
      50: 0.048851155289608,
      100: 0.0354621760592113,
      200: 0.025584358256487003,
      500: 0.0164519238025286,
      1000: 0.0117439009052552,
      2000: 0.008355737247680059,
      5000: 0.0053123924740821294,
      10000: 0.00376734715752209,
      20000: 0.00266863168718114,
      40000: 0.00189061261635977,
      72000: 0.00141049709228472},
     '0.6': {4: 0.125,
      5: 0.134318918697053,
      6: 0.13186973390253,
      7: 0.124216086833531,
      8: 0.11592005574998801,
      9: 0.10800780236193198,
      10: 0.102180866696628,
      15: 0.0881198482202905,
      20: 0.0776460662880254,
      30: 0.0649164408053978,
      50: 0.0516145897865757,
      100: 0.0374805844550272,
      200: 0.0270252129816288,
      500: 0.017383057902553,
      1000: 0.012405033293814,
      2000: 0.00882439333812351,
      5000: 0.00560929919359959,
      10000: 0.00397885007249132,
      20000: 0.0028181999035216,
      40000: 0.00199645471886179,
      72000: 0.00148936709298802},
     '0.7': {4: 0.13255954878268902,
      5: 0.14729879897625198,
      6: 0.140564796497941,
      7: 0.130409013968317,
      8: 0.120561479262465,
      9: 0.112512617124951,
      10: 0.10996094814295099,
      15: 0.093124666680253,
      20: 0.0824558407118372,
      30: 0.0689178762425442,
      50: 0.0548121932066019,
      100: 0.0398046179116599,
      200: 0.0286920262150517,
      500: 0.0184503949887735,
      1000: 0.0131684179320803,
      2000: 0.009367858207170609,
      5000: 0.00595352728377949,
      10000: 0.00422430013176233,
      20000: 0.00299137548142077,
      40000: 0.00211929748381704,
      72000: 0.00158027541945626},
     '0.8': {4: 0.15749736904023498,
      5: 0.161085025702604,
      6: 0.14941924112913002,
      7: 0.136639642123068,
      8: 0.125558759034845,
      9: 0.12291503348081699,
      10: 0.11884476721158699,
      15: 0.0996694393390689,
      20: 0.08834462700173701,
      30: 0.0739249074078291,
      50: 0.0588230482851366,
      100: 0.0427283846799166,
      200: 0.0308006766341406,
      500: 0.0198162679782071,
      1000: 0.0141377942603047,
      2000: 0.01005604603884,
      5000: 0.00639092280563517,
      10000: 0.00453437508148542,
      20000: 0.00321024899920135,
      40000: 0.0022745769870358102,
      72000: 0.00169651643860074},
     '0.9': {4: 0.18740187880755899,
      5: 0.176811998476076,
      6: 0.159137064572627,
      7: 0.144240669035124,
      8: 0.141841067033899,
      9: 0.136412639387084,
      10: 0.130462149644819,
      15: 0.11008749690090598,
      20: 0.0972346018122903,
      30: 0.0814791379390127,
      50: 0.0649136324046767,
      100: 0.047152783315718,
      200: 0.0339967814293504,
      500: 0.0218781313182203,
      1000: 0.0156148055023058,
      2000: 0.0111019116837591,
      5000: 0.00705566126234625,
      10000: 0.00500178808402368,
      20000: 0.00354362220314155,
      40000: 0.00250999080890397,
      72000: 0.0018730618472582602},
     '0.95': {4: 0.20726978858735998,
      5: 0.18639179602794398,
      6: 0.164769608513302,
      7: 0.159903395678336,
      8: 0.153978303998561,
      9: 0.14660378495401902,
      10: 0.139611395137099,
      15: 0.118760769203664,
      20: 0.105130218270636,
      30: 0.0881689143126666,
      50: 0.0702737877191269,
      100: 0.0511279442868827,
      200: 0.0368418413878307,
      500: 0.0237294742633411,
      1000: 0.0169343970067564,
      2000: 0.0120380990328341,
      5000: 0.0076506368153935,
      10000: 0.00542372242836395,
      20000: 0.00384330190244679,
      40000: 0.00272375073486223,
      72000: 0.00203178401610555},
     '0.98': {4: 0.22375580462922195,
      5: 0.19361253363045,
      6: 0.17917654739278197,
      7: 0.17519655327122302,
      8: 0.16597856724751,
      9: 0.157084065653166,
      10: 0.150961728882481,
      15: 0.128890475210055,
      20: 0.11430970428125302,
      30: 0.0960564383013644,
      50: 0.0767095886079179,
      100: 0.0558022052195208,
      200: 0.0402729850316397,
      500: 0.025919578977657003,
      1000: 0.018513067368104,
      2000: 0.0131721010552576,
      5000: 0.00836821687047215,
      10000: 0.00592656681022859,
      20000: 0.00420258799378253,
      40000: 0.00298072958568387,
      72000: 0.00222356097506054},
     '0.99': {4: 0.231796258864192,
      5: 0.19650913979884502,
      6: 0.191862827995563,
      7: 0.184118659121501,
      8: 0.172988528276759,
      9: 0.164164643657217,
      10: 0.159684158858235,
      15: 0.13598356863636,
      20: 0.120624043335821,
      30: 0.101478558893837,
      50: 0.0811998415355918,
      100: 0.059024132304226,
      200: 0.0426864799777448,
      500: 0.0274518022761997,
      1000: 0.0196080260483234,
      2000: 0.0139655122281969,
      5000: 0.00886357892854914,
      10000: 0.00628034732880374,
      20000: 0.00445774902155711,
      40000: 0.00315942194040388,
      72000: 0.00235782814777627},
     '0.995': {4: 0.23726374382677898,
      5: 0.198159967287576,
      6: 0.20210197104296804,
      7: 0.19101439617430602,
      8: 0.179010413496374,
      9: 0.172821674582338,
      10: 0.16719524735674,
      15: 0.14245248368127697,
      20: 0.126552378036739,
      30: 0.10650487144103,
      50: 0.0852854646662134,
      100: 0.0620425065165146,
      200: 0.044958959158761,
      500: 0.0288986369564301,
      1000: 0.0206489568587364,
      2000: 0.0146889122204488,
      5000: 0.00934162787186159,
      10000: 0.00661030641550873,
      20000: 0.00469461513212743,
      40000: 0.0033273652798148,
      72000: 0.00248343580127067},
     '0.998': {4: 0.241992892688593,
      5: 0.19924427936243302,
      6: 0.213015781111186,
      7: 0.198216795232182,
      8: 0.186504388711178,
      9: 0.182555283567818,
      10: 0.175419540856082,
      15: 0.15017281653074202,
      20: 0.13360135382395,
      30: 0.112724636524262,
      50: 0.0904847827490294,
      100: 0.0658016011466099,
      200: 0.0477643873749449,
      500: 0.0306813505050163,
      1000: 0.0219285176765082,
      2000: 0.0156076779647454,
      5000: 0.009932186363240291,
      10000: 0.00702254699967648,
      20000: 0.004994160691291679,
      40000: 0.00353988965698579,
      72000: 0.00264210826339498},
     '0.999': {4: 0.244369839049632,
      5: 0.199617527406166,
      6: 0.219518627282415,
      7: 0.20234101074826102,
      8: 0.19448404115794,
      9: 0.188658833121906,
      10: 0.180611195797351,
      15: 0.15545613369632802,
      20: 0.138569903791767,
      30: 0.117164140184417,
      50: 0.0940930106666244,
      100: 0.0684479731118028,
      200: 0.0497198001867437,
      500: 0.0320170996823189,
      1000: 0.0228689168972669,
      2000: 0.0162685615996248,
      5000: 0.0103498795291629,
      10000: 0.0073182262815645795,
      20000: 0.00520917757743218,
      40000: 0.00369400045486625,
      72000: 0.0027524322157581},
     '0.9995': {4: 0.245966625504691,
      5: 0.19980094149902802,
      6: 0.22433904739444602,
      7: 0.205377566346832,
      8: 0.200864297005026,
      9: 0.19408912076824603,
      10: 0.18528641605039603,
      15: 0.160896499106958,
      20: 0.14336916123968,
      30: 0.12142585990898701,
      50: 0.0974904344916743,
      100: 0.0709169443994193,
      200: 0.0516114611801451,
      500: 0.0332452747332959,
      1000: 0.023738710122235003,
      2000: 0.0168874937789415,
      5000: 0.0107780907076862,
      10000: 0.0076065423418208,
      20000: 0.005403962359243721,
      40000: 0.00383345715372182,
      72000: 0.0028608570740143},
     '0.9998': {4: 0.24743959723326198,
      5: 0.19991708183427104,
      6: 0.22944933215424101,
      7: 0.208306562526874,
      8: 0.20884999705022897,
      9: 0.19915700809389003,
      10: 0.19120308390504398,
      15: 0.16697940794624802,
      20: 0.148940116394883,
      30: 0.126733051889401,
      50: 0.10228420428399698,
      100: 0.0741183486081263,
      200: 0.0540543978864652,
      500: 0.0348335698576168,
      1000: 0.0248334158891432,
      2000: 0.0176505093388153,
      5000: 0.0113184316868283,
      10000: 0.00795640367207482,
      20000: 0.00564540201704594,
      40000: 0.0040079346963469605,
      72000: 0.00298695044508003},
     '0.9999': {4: 0.24823065965663801,
      5: 0.19995902909307503,
      6: 0.232714530449602,
      7: 0.209866047852379,
      8: 0.212556040406219,
      9: 0.20288159843655804,
      10: 0.19580515933918397,
      15: 0.17111793515551002,
      20: 0.152832538183622,
      30: 0.131198578897542,
      50: 0.104680624334611,
      100: 0.0762579402903838,
      200: 0.0558704526182638,
      500: 0.0359832389317461,
      1000: 0.0256126573433596,
      2000: 0.0181944265400504,
      5000: 0.0117329446468571,
      10000: 0.0082270524584354,
      20000: 0.00580460792299214,
      40000: 0.00414892737222885,
      72000: 0.00309340092038059},
     '0.99995': {4: 0.248754269146416,
      5: 0.19997839537608197,
      6: 0.236548128358969,
      7: 0.21096757693345103,
      8: 0.21714917413729898,
      9: 0.205979795735129,
      10: 0.20029398089673,
      15: 0.17590050570443203,
      20: 0.15601016361897102,
      30: 0.133691739483444,
      50: 0.107496694235039,
      100: 0.0785735967934979,
      200: 0.0573877056330228,
      500: 0.0369051995840645,
      1000: 0.0265491336936829,
      2000: 0.0186226037818523,
      5000: 0.0119995948968375,
      10000: 0.00852240989786251,
      20000: 0.00599774739593151,
      40000: 0.0042839159079761,
      72000: 0.00319932767198801},
     '0.99998': {4: 0.24930203997425898,
      5: 0.199993151405815,
      6: 0.2390887911995,
      7: 0.212233348558702,
      8: 0.22170007640450304,
      9: 0.21054115498898,
      10: 0.20565108964621898,
      15: 0.18185667601316602,
      20: 0.16131922583934502,
      30: 0.137831637950694,
      50: 0.11140887547015,
      100: 0.0813458356889133,
      200: 0.0593365901653878,
      500: 0.0387221159256424,
      1000: 0.027578430100535997,
      2000: 0.0193001796565433,
      5000: 0.0124410052027886,
      10000: 0.00892863905540303,
      20000: 0.00633099254378114,
      40000: 0.0044187010443287895,
      72000: 0.00332688234611187},
     '0.99999': {4: 0.24945965232322498,
      5: 0.199995525025673,
      6: 0.24010356643629502,
      7: 0.21266103831250602,
      8: 0.225000835357532,
      9: 0.21180033095039003,
      10: 0.209682048785853,
      15: 0.185743454151004,
      20: 0.165568255916749,
      30: 0.14155750962435099,
      50: 0.113536607717411,
      100: 0.0832963013755522,
      200: 0.0607646310473911,
      500: 0.039930259057650005,
      1000: 0.0284430733108,
      2000: 0.0196241518040617,
      5000: 0.0129467396733128,
      10000: 0.009138539330002129,
      20000: 0.00656987109386762,
      40000: 0.00450818604569179,
      72000: 0.00339316094477355},
     '1': {4: 0.24974836247845,
      5: 0.199999835639211,
      6: 0.24467288361776798,
      7: 0.21353618608817,
      8: 0.23377291968768302,
      9: 0.21537991431762502,
      10: 0.221530282182963,
      15: 0.19224056333056197,
      20: 0.175834459522789,
      30: 0.163833046059817,
      50: 0.11788671686531199,
      100: 0.0926780423096737,
      200: 0.0705309107882395,
      500: 0.0431448163617178,
      1000: 0.0313640941982108,
      2000: 0.0213081254074584,
      5000: 0.014396063834027,
      10000: 0.00952234579566773,
      20000: 0.006858294480462271,
      40000: 0.00513477467565583,
      72000: 0.00376331697005859}}

    qDiptab_df = pd.DataFrame(qDiptab_dict)

    diptable = np.array(qDiptab_df)
    ps = np.array(qDiptab_df.columns).astype(float)
    Ns = np.array(qDiptab_df.index)

    if N >= Ns[-1]:
        dip = transform_dip_to_other_nbr_pts(dip, N, Ns[-1]-0.1)
        N = Ns[-1]-0.1

    iNlow = np.nonzero(Ns < N)[0][-1]
    qN = (N-Ns[iNlow])/(Ns[iNlow+1]-Ns[iNlow])
    dip_sqrtN = np.sqrt(N)*dip
    dip_interpol_sqrtN = (
        np.sqrt(Ns[iNlow])*diptable[iNlow, :] + qN*(
            np.sqrt(Ns[iNlow+1])*diptable[iNlow+1, :]-np.sqrt(Ns[iNlow])*diptable[iNlow, :]))

    if not (dip_interpol_sqrtN < dip_sqrtN).any():
        return 1

    iplow = np.nonzero(dip_interpol_sqrtN < dip_sqrtN)[0][-1]
    if iplow == len(dip_interpol_sqrtN) - 1:
        return 0

    qp = (dip_sqrtN-dip_interpol_sqrtN[iplow])/(dip_interpol_sqrtN[iplow+1]-dip_interpol_sqrtN[iplow])
    p_interpol = ps[iplow] + qp*(ps[iplow+1]-ps[iplow])

    return 1 - p_interpol
dip     -   dip value computed from dip_from_cdf
        N       -   number of observations