imports.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from IPython.lib.deepreload import reload as dreload
  2. import PIL, os, numpy as np, math, collections, threading, json, bcolz, random, scipy, cv2
  3. import pandas as pd, pickle, sys, itertools, string, sys, re, datetime, time, shutil, copy
  4. import seaborn as sns, matplotlib
  5. import IPython, graphviz, sklearn_pandas, sklearn, warnings, pdb
  6. import contextlib
  7. from abc import abstractmethod
  8. from glob import glob, iglob
  9. from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
  10. from itertools import chain
  11. from functools import partial
  12. from collections import Iterable, Counter, OrderedDict
  13. from isoweek import Week
  14. from pandas_summary import DataFrameSummary
  15. from IPython.lib.display import FileLink
  16. from PIL import Image, ImageEnhance, ImageOps
  17. from sklearn import metrics, ensemble, preprocessing
  18. from operator import itemgetter, attrgetter
  19. from pathlib import Path
  20. from distutils.version import LooseVersion
  21. from matplotlib import pyplot as plt, rcParams, animation
  22. from ipywidgets import interact, interactive, fixed, widgets
  23. matplotlib.rc('animation', html='html5')
  24. np.set_printoptions(precision=5, linewidth=110, suppress=True)
  25. from ipykernel.kernelapp import IPKernelApp
  26. def in_notebook(): return IPKernelApp.initialized()
  27. def in_ipynb():
  28. try:
  29. #cls = get_ipython().__class__.__name__
  30. #return cls == 'ZMQInteractiveShell'
  31. return False
  32. except NameError:
  33. return False
  34. import tqdm as tq
  35. from tqdm import tqdm_notebook, tnrange
  36. def clear_tqdm():
  37. inst = getattr(tq.tqdm, '_instances', None)
  38. if not inst: return
  39. try:
  40. for i in range(len(inst)): inst.pop().close()
  41. except Exception:
  42. pass
  43. if in_notebook():
  44. def tqdm(*args, **kwargs):
  45. clear_tqdm()
  46. return tq.tqdm(*args, file=sys.stdout, **kwargs)
  47. def trange(*args, **kwargs):
  48. clear_tqdm()
  49. return tq.trange(*args, file=sys.stdout, **kwargs)
  50. else:
  51. from tqdm import tqdm, trange
  52. tnrange=trange
  53. tqdm_notebook=tqdm