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

multiunion error on C but pass on python #24

Closed
xueyumusic opened this issue Feb 27, 2016 · 5 comments · Fixed by #160
Closed

multiunion error on C but pass on python #24

xueyumusic opened this issue Feb 27, 2016 · 5 comments · Fixed by #160
Assignees

Comments

@xueyumusic
Copy link
Contributor

I met a problem about multiunion function that when using default C implementation it reports error but could work correctly when using python implementation... For example

fwd_index = OOBTree()
tp = (1,2,3)
fwd_index["a"] = tp

IF.multiunion(self._fwd_index.values(("a",))
@xueyumusic
Copy link
Contributor Author

It seems that C implement does not support tuple value type, but python implement could compatible with tuple...

@tseaver
Copy link
Member

tseaver commented Mar 1, 2016

I'm not clear what issue you are reporting. Can you show a traceback?

@xueyumusic
Copy link
Contributor Author

The issue I want to report could be shown as this example. If I use C implement, it reports an error, however if I use Python implement, it is right

Use C multiunion:

In [1]: import BTrees

In [2]: from BTrees.OOBTree import OOBTree

In [3]: from BTrees.IFBTree import IFSet

In [4]:

In [4]:  t=OOBTree()

In [5]: t["a"]=(1,2,3)

In [6]: t["b"]=IFSet((4,5,6))

In [7]: BTrees.family32.IF.multiunion(t.values())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-b83097e5a1a2> in <module>()
----> 1 BTrees.family32.IF.multiunion(t.values())

TypeError: invalid argument

Use Python multiunion:

In [1]: import BTrees

In [2]: from BTrees.OOBTree import OOBTree

In [3]: from BTrees.IFBTree import IFSet

In [4]:

In [4]: t=OOBTree()

In [5]: t["a"]=(1,2,3)

In [6]: t["b"]=IFSet((4,5,6))

In [7]: BTrees.family32.IF.multiunion(t.values())
Out[7]: BTrees.IFBTree.IFSet([1, 2, 3, 4, 5, 6])

@jamadden
Copy link
Member

jamadden commented Mar 6, 2016

Looks to me like the C implementation is "right". But I think that's undefined behavior (what is a union of a typed, ordered set, and a random tuple even supposed to mean?) so don't be surprised at either outcome, or if it formats your hard drive.

@jamadden
Copy link
Member

jamadden commented Apr 5, 2021

The interface definition for multiuniion explicitly spells out which types can be used as arguments (sets and tree sets, buckets and btrees, single integers).

The online help, however, simply says "Each [argument] must be an integer set, or convertible to one via the set iteration protocol." Now, it's talking about the internal set iteration protocol using the C SetIteration struct, but it's very reasonable to imagine that it means "anything you can use as a constructor to a set" e.g., "any iterable of integers."

I don't think it would be hard to extend the internal SetIteration protocol to support arbitrary iterables of integers.

@jamadden jamadden self-assigned this Apr 5, 2021
jamadden added a commit that referenced this issue Apr 5, 2021
…h arbitrary iterables.

The Python implementation already did this, so this only updates the C version to match.

For multiunion, all arguments can be arbitrary iterables. The others derive their return type from the first argument, so it must still be a BTree object, but the second can be anything.

Fixes #24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants