Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support explicit infinity parsing from strings #3

Closed
wants to merge 1 commit into from

Conversation

xmjw
Copy link

@xmjw xmjw commented Aug 29, 2018

When we call I.to_string with an infinity we render (123,inf), but we cannot parse that back in 馃様. This change allows us to parse this back into an interval.

For example:

>>> import intervals as I
>>> I.__version__
'1.5.5'
>>> ival = I.open(50,I.inf)
>>> ival
(50,+inf)
>>> istr = I.to_string(ival)
>>> istr
'(50,+inf)'
>>> inew = I.from_string(istr, conv=int)
>>> inew
(50,+inf)
>>> inew == ival
True

Hope this looks okay? I'm not especially skilled-up on Python...

So that we can parse strings of intervals with infinity, that are
created _from_ an interval we generate with I.to_string().

Includes a minor version bump.
@AlexandreDecan
Copy link
Owner

Thanks for submitting! I'll have a look asap!

@AlexandreDecan AlexandreDecan self-assigned this Aug 29, 2018
@AlexandreDecan
Copy link
Owner

As a temporary workaround, the desired behaviour can be obtained by providing an appropriate conv function (e.g. the conv_with_infinity your provide in this pull request).

I'll add support for custom string representation/parsing for (positive/negative) infinity to from_string and to_string, probably by adding two new parameters pinf et ninf that could be used to specify the representation to use/parse for infinities. I hope to release this change tomorrow.

@AlexandreDecan
Copy link
Owner

I updated the two functions with pinf and ninf parameters. These can be used to specify which is the representation of a positive/negative infinity.

I also updated the documentation to add an example using +oo and -oo.
Release 1.6.0 will be on PyPi in a few minutes (I'm waiting for Travis to test the library on all Python versions first).

@xmjw
Copy link
Author

xmjw commented Aug 30, 2018

Awesome - I've been using that workaround actually, I thought I should offer it back. Thanks for doing that, it's super helpful and cleans up my code a little.

@AlexandreDecan
Copy link
Owner

You're welcome ;) I'm glad to see someone is using this library ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants