<jupyter_start><jupyter_text>Error Suppression<jupyter_code>from IPython import InteractiveShell

from htools import hdir
hdir(InteractiveShell.ast_node_interactivity, True, True)

tmp = InteractiveShell.ast_node_interactivity
InteractiveShell.ast_node_interactivity
'a'
1
InteractiveShell.ast_node_interactivity = 'all'
'b'
2
'c'
3
InteractiveShell.ast_node_interactivity = tmp
1
2
3
from htools import magics
1
2
3
magics.InteractiveMagic??
%%talk
1
2
3
1
2
3
%%mute
1
2
3
1
2
3
%%hush
1
2
3
1
2
3
%%talk -p
1
2
3
1
2
3
%%mute -p
1
2
3
1
2
3
%%hush -p
1
2
3
1
2
3<jupyter_output><empty_output><jupyter_text>Older code<jupyter_code>from IPython.core.magic_arguments import (magic_arguments, parse_argstring, 
                                          argument, kwds)
from IPython.core.magic import cell_magic, magics_class, Magics
import numpy as np
from sklearn.ensemble import RandomForestClassifier
import warnings

from htools import hdir, magics
%%talk

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
# @magics_class
# class WarningMagic(Magics):
    
#     @cell_magic
#     @magic_arguments()
#     @argument('-A', action='store_true', help='Warning mode: always.')
#     @argument('-P', action='store_true', help='Boolean flag. If passed, the '
#               'change will apply for the rest of the notebook, or until the '
#               'user changes it again. The default behavior is to apply the '
#               'change only to the current cell.')
#     def warn(self, line, cell):
#         """Silence warnings for a cell. If the default has been changed to 
#         hide warnings, the -A flag can be used to show all warnings for a 
#         cell. The -P flag will make the change persist, at least until the
#         user changes it again.
#         """
#         args = parse_argstring(self.warn, line)
#         flags = {flag for flag in hdir(args).keys() if getattr(args, flag)}
        
#         # Default is to ignore warnings. This is because warnings alerts you
#         # by default, so the typical use case is to silence warnings.
#         if 'A' in flags:
#             mode = 'always'
#         else:
#             mode = 'ignore'
        
#         # Change mode and run cell.
#         warnings.filterwarnings(mode)
#         get_ipython().run_cell(cell)
    
#         # Reset mode if change is note permanent.
#         if 'P' not in flags:
#             warnings.resetwarnings()
# get_ipython().register_magics(WarningMagic)
%%talk
%%lax

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk
%%lax -p

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk
%%nag

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk
%%nag -p

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk
%%lax

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)
%%talk

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)

rf = RandomForestClassifier()
x = np.random.randint(0, 10, (10, 3))
y = np.random.randint(0, 2, 10)
rf.fit(x, y)<jupyter_output>/Users/hmamin/anaconda3/lib/python3.7/site-packages/sklearn/ensemble/forest.py:245: FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22.
  "10 in version 0.20 to 100 in 0.22.", FutureWarning)<jupyter_text>Verbosity<jupyter_code>1+2
2+3
%%mute
3+4
4+5
from htools import magics
1+2
2+3
%%mute
2+3
3+4
%%talk
4+5
5+6<jupyter_output><empty_output><jupyter_text>Alerts<jupyter_code>import os
import subprocess

import htools
@magics_class
class AlerterMagic(Magics):
    
    @cell_magic
    def alert(self, line=None, cell=None):
        text = '"Cell execution complete"'
        title = '"Jupyter Alert"'
        msg = f"osascript -e 'display notification {text} with title {title}'"
        print(msg)
        os.system(f"osascript -e 'display notification {text} "
                  f"with title {title}'")
ip = get_ipython()
ip.register_magics(AlerterMagic)
%%alert
j = 1
for i in range(1, 10_000_000):
    j += 1
print(j)
j * 2
os.system('subl')
subprocess.run('subl')
os.system('ls')
text = '"Cell execution complete"'
title = '"Jupyter Alert"'
msg = f"osascript -e 'display notification {text} with title {title}'"
! {msg}
msg
text = 'cell exec complete'
title = 'jupyter alert'
os.system("""
              osascript -e 'display notification "{}" with title "{}"'
              """.format(text, title))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15091700341933478, 'fraction_numerical': 0.05051290021759403, 'mean_word_length': 3.481197771587744, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '231445', 'license': 'MIT', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2532, 'n_words': 703, 'path': 'notebooks/scratch_magics.ipynb', 'repo_name': 'hdmamin/htools', 'size': '6434'}