-
Notifications
You must be signed in to change notification settings - Fork 12
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
Type confusion with Tuple #17
Comments
I have added a document warning the user about type confusion to #71. Regarding the issues above: I think we can make For composition, I think we should just not use I'm also thinking using Some of the ideas of syntactic sugar from #14 may also be bad ideas. They should be considered carefully. Sugar is nice and can really make code more readable, but it should only be used if it is completely unambiguous, and there is no possibility for the user to try using it to do something it doesn't do. |
c.f. issue Quansight-Labs#17.
…edError These only work in NumPy as fancy indices. However, there is too much of a risk of API confusion in thinking that Tuple() works like Tuple((1, 2, 3)) instead of Tuple(1, 2, 3). So we make this an unconditional error with helpful error messages. Fancy indices should use either a list or array. c.f. issue Quansight-Labs#17.
In #74 I have made Tuple(tuple) give ValueError instead of NotImplementedError, with a hint in the error message to either use Tuple(*args) or use a list for fancy indexing. tuples inside of tuple indices do fancy indexing, but there is too much risk for confusion of Tuple(tuple) rather than the correct Tuple(*tuple), that I think it is best to just disallow it inside of ndindex. We could potentially allow it in |
There's a lot of potential for type confusion with Tuple:
Tuple(tuple)
is currently not valid. To create a Tuple from a tuple, you have to useTuple(*tuple)
. But there are valid slices with nested tuples, so we can't make it work.len(t)
gives ValueError becauselen
in ndindex means the number of elements indexed by the index for a single axis. For a Tuple, this isn't implemented, but we could make it assume there are as many axes as elements of the tuple. But people might expect it to meanlen(Tuple.args)
.t[0]
doesn't work, but it eventually will mean composed indices (a[t][0]
), but people might expectt.args[0]
.I don't know if there are good solutions here, other than documentation, unless we want to give up some of the nice syntactic sugar. It's unfortunate that tuple is an index that itself can be indexed.
The text was updated successfully, but these errors were encountered: