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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wierd bug with flatten and partition #124

Closed
cdoool opened this issue Mar 10, 2018 · 4 comments
Closed

Wierd bug with flatten and partition #124

cdoool opened this issue Mar 10, 2018 · 4 comments
Assignees
Labels

Comments

@cdoool
Copy link

cdoool commented Mar 10, 2018

Hi! First of all, thanks for the great library. Thanks to it I no longer want to migrate back to Scala.

On a first day of using it, I encountered a strange bug:
val = seq([1,2,3,4,5,6]).partition(lambda x:x>2)
(val = [[3, 4, 5, 6], [1, 2]])
But
val = seq([[1,2,3],[4,5,6]]).flatten().partition(lambda x:x>2)
(val = [[3, 4, 5, 6], []])

Surely, it's a bug?

@EntilZha
Copy link
Owner

EntilZha commented Mar 10, 2018

Thanks @cdoool for opening an issue! I agree that the behavior seems wrong. I did a little more debugging and I think this example shows that it is due to the sequence being consumed twice in partition. The culprit is that there are two filter calls in the implementation https://github.com/EntilZha/PyFunctional/blob/master/functional/transformations.py#L672. It shouldn't be too hard to rewrite that to do only a single pass/consume the sequence once. I could probably have a fix this weekend and make use of the fancy new travis auto publish to pypi to get the fix out shortly after.

Thanks for the bug report!

In [36]: a, b = seq([[1, 2, 3], [4, 5, 6]]).flatten().partition(lambda x: x > 2)
In [37]: a
Out[37]: [3, 4, 5, 6]
In [38]: b
Out[38]: []
In [39]: a, b = seq([[1, 2, 3], [4, 5, 6]]).flatten().partition(lambda x: x > 2)
In [40]: b
Out[40]: [1, 2]
In [41]: a
Out[41]: [] 

@EntilZha EntilZha self-assigned this Mar 10, 2018
@EntilZha EntilZha added the bug label Mar 10, 2018
EntilZha added a commit that referenced this issue Apr 1, 2018
@EntilZha
Copy link
Owner

EntilZha commented Apr 1, 2018

@cdoool I believe I've fixed the issue on master. I included the example above in the tests, but it would be great if you can verify for your specific use case that it works that would be great. If everything looks good I can push out a minor release on PyPI

@cdoool
Copy link
Author

cdoool commented Apr 5, 2018

Can confirm everything works fine now. Many thanks!

@EntilZha
Copy link
Owner

EntilZha commented Apr 6, 2018

Thanks, new version should be out on pypi now

@EntilZha EntilZha closed this as completed Apr 6, 2018
drachpy pushed a commit to drachpy/PyFunctional that referenced this issue Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants