Code Monkey home page Code Monkey logo

frosch's Introduction

Hi ๐Ÿค—, I'm Patrick Haller
I am a PhD Student and currently deep diving into the field of Natural Language Processing.
In the mean time, I am looking to contribute to great Open Source projects.

~ Profile ยท website ยท linkedin ~

frosch's People

Contributors

dependabot[bot] avatar gvx avatar hallerpatrick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

frosch's Issues

TypeError: hook() got an unexpected keyword argument 'theme'

Hi there,

just found out about frosch and wanted to give it a try, because I really like the idea!

But I've encountered a problem pretty soon. Using hook() without any config works just fine, but I think I'm just plain dumb or blind or both, but trying to configure hook with the theme argument raises an exception on my side.

image

What am I missing?

Print Debugging

Almost everything implement but the interface

from frosch import fprint as fp

fp(some_var)

CI pipeline

Use github actions, add linter and tests. Also write some tests...

More configurability

This means for colours and maybe symbols. Frosch will in the future allow for way more configuration options for different purposes. We should therefore come up with a better config manager.

Multiline still not working with single parsable lines in statement

from frosch import hook

hook()

x = (
    3 +
    "String")
  File "C:\Users\user\venv37\lib\site-packages\frosch\frosch.py", line 118, in get_whole_expression
    raise SyntaxError("SyntaxError in line:{}".format(stack.lineno)) from error
SyntaxError: SyntaxError in line:8

Original exception was:
Traceback (most recent call last):
  File "main.py", line 8, in <module>
    "Striong")
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Tested in cmd

Custom coloring

Allow for custom coloring which will can be passed in the hook function. Using the color themes from pygments

Values with large reprs

Example script:

from frosch import hook

hook()
x = list(range(10000))
x/0

Output:

Traceback (most recent call last):
  File "/home/alex/.config/JetBrains/PyCharm2020.3/scratches/scratch_1099.py", line 5, in <module>
    x/0
TypeError: unsupported operand type(s) for /: 'list' and 'int'

 5 || x / 0
   || โ”‚
   || โ””โ”€โ”€ x: list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ... this goes on and prints the whole list, up to 9999

I suggest https://github.com/alexmojaki/cheap_repr to print truncated reprs without losing too much information.

This also relates to #14

Allign for line number

Linenumber have different lenght, which is not considered now and destroy the formatting

Parsing error when exception occurs inside except handler

Example script:

from frosch import hook

hook()

try:
    1/0
except Exceptoin:
    pass

Output:

Error in sys.excepthook:
Traceback (most recent call last):
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 115, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 103, in parse_string
    return self.parse_tokens(tokens, debug)
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 71, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/parse.py", line 162, in addtoken
    raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=1, value='except', context=('', (1, 0))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 121, in ParseCodeToTree
    tree = parser_driver.parse_string(code, debug=False)
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 103, in parse_string
    return self.parse_tokens(tokens, debug)
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 71, in parse_tokens
    if p.addtoken(type, value, (prefix, start)):
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/parse.py", line 162, in addtoken
    raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=1, value='except', context=('', (1, 0))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/frosch/parser.py", line 180, in format_line
    formatted_line, _ =  FormatCode(line)
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/yapf_api.py", line 147, in FormatCode
    tree = pytree_utils.ParseCodeToTree(unformatted_source)
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 127, in ParseCodeToTree
    raise e
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 125, in ParseCodeToTree
    ast.parse(code)
  File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    except Exceptoin :
    ^
SyntaxError: invalid syntax

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/frosch/parser.py", line 196, in format_line
    raise ParseError("Could not parse line: {}".format(line)) from error
frosch.parser.ParseError: Could not parse line: except Exceptoin :

Original exception was:
Traceback (most recent call last):
  File "/home/alex/.config/JetBrains/PyCharm2020.3/scratches/scratch_1099.py", line 6, in <module>
    1/0
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/.config/JetBrains/PyCharm2020.3/scratches/scratch_1099.py", line 7, in <module>
    except Exceptoin:
NameError: name 'Exceptoin' is not defined

Doesn't work with multiline statements

Example script:

import frosch

frosch.hook()

x = (
  1 +
  "2"
)

Output:

Error in sys.excepthook:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/frosch/frosch.py", line 47, in pytrace_excepthook
    names = parse_error_line(last_stack.line)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/frosch/frosch.py", line 71, in parse_error_line
    tree = ast.parse(line)
  File "/usr/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    1 +
      ^
SyntaxError: invalid syntax

Original exception was:
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    1 +
TypeError: unsupported operand type(s) for +: 'int' and 'str'

In general you may be interested in using https://github.com/alexmojaki/stack_data as part of this library

array/tensor refinement

Hi,

Great project!
I think it would be relatively easy to make it even more awesome. :)

Many people deal with data science nowadays, and there
tensor properties, like shape, are more frequent source of error
than e.g. values in the array.

Currently arrays / tensors are displayed like this:

x: ndarray = array([ 1, 2...  ])
y: Tensor = tensor([ 1, 2...  ])

I would recommend at least two extra piece of information: shape and dtype, something like this:

x: ndarray[float64] (200,300) = array([ 1, 2...  ])

Or maybe:

x: Tensor, cpu/f32, 2d, (200,300) = array([ 1, 2...  ])

Maybe it would be even nicer to make the hook configurable, like:

import frosch
frosch.hook(array_shapes=True, array_types=True, array_device=False, requires_grad=True, array_values=False)

Of course, you can always add almost infinite useful tricks to numpy/pytorch, e.g.
isnan/isinf, so here is a final variant to consider:

x: Tensor, type=cpu/f32, grad=F, shape=(200,300), inf:0 NaN:0, min: -3, max:1e8, mean: 0.0001

Of course, these might take time to print, but if it is configurable, then it doesn't really matter.

Another way, which would be also cool, is having a configurable extra printer.
E.g.

import frosch
import my_tricks
frosch.hook( (np.ndarray, my_tricks.numpy_printer) )

In this case anybody could customize their own printer, and add an extra representation.
I imagine the print like this:

x: ndarray "Whatever string the function returned"

And the function interface would be:

        extra_info = ....
        return extra_info + default_printers_text

This might mess up colors, i see it.

There could be other ways to define values, like returning a dictionary of texts,
like "pre_type", "post_type", "pre_value", "post_value" , and format them something like this:

f'{pre_type}{type}{post_type} = {pre_value}{value}{post_value}

In this way you don't have much issues with the coloring, it is still controlled by you,
but people could customize the printer.

Which one to choose?
Well, i like my own printers, e.g. testing for NaNs, but for most people a reasonable built-in would be the easiest,
maybe with some verbosity parameter in the hook installer.

But once again: it is a great project already, and much more readable than any default.
I really appreciate your efforts, and even if you don't incorporate anything from the above,
it is already a lot of help for lot of people. But maybe the above could make it even better. :)

Hook/provide hook for logging.exception

It would be nice if there was a way to get logging.exception to do the equivalent of what frosch does, but into the log stream. Or maybe there is and I don't know it?

print frosch debug info from an exception handler

I realized there's no way to explicitly make frosch print. eg. I'd like to be able to:

try:
    foo()
except SomeError as e:
    frosch.print(e)

to get the nice frosch output while letting my code potentially survive. I suspect it's probably possible, but just not documented?

Gitpod

For fast testing and show off

Get IndexError when pressing CTRL-C

When I interrupt the keyboard (ctrl + c), I get

Error in sys.excepthook:
Traceback (most recent call last):
  File "REDACTED/.venv/lib/python3.6/site-packages/frosch/frosch.py", line 56, in pytrace_excepthook
    parsed_exception = ParsedException(traceback_, error_type, error_message)
  File "REDACTED/.venv/lib/python3.6/site-packages/frosch/parser.py", line 68, in __init__
    self.last_stack = traceback.extract_tb(traceback_)[-1]
IndexError: list index out of range

Original exception was:
KeyboardInterrupt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.