-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: Additions to np.farray API #14966
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
Conversation
69301dc
to
fb09cbf
Compare
- Added `copy=False` parameter - Added `dtype=None` option
To be honest, I am not too convinced right now. Another thing, you mentioned |
@seberg. The use-case I have in my actual project (which does use I don't see this being an uncommon function being a problem. If the the limited interface is the issue, then this will make more common. If not, then this change does not affect that many people. |
I am just not sure I like the whole dance of first creating an array. The main issue though is that I have never used this function, and the whole way it works (replacing the input |
@seberg. I don't like that particular dance either. If there was a reasonable way to assess the dtype without creating an array, I'd be happy to use that instead. I've used this function quite a bit in certain situations where I need to do operations on floating point numbers. |
Can you give an example of when you care about the numbers being floating point? |
The specific example I have is a small scikit I'm working on. I do a whole bunch of in-place floating-point math on the inputs (division, fractional exponents, etc.), so it's very convenient to be able to create a copy as I convert the input to float. |
I would personally (at this time at least) probably opt for a pattern such as:
Not sure if that is what you are looking for. |
@seberg That doesn't allow passing in arbitrary array-like objects that may not have a |
I am sorry, but I think I will close this for now (for now, happy to reopen). I am still not convinced and it has been a while. This just does not feel like a neat API where extending it actually helps the general user. I am sure it can be useful to have a helper for it for libraries, but I doubt this is it to be honest. I am more likely to accept deprecating it with a message: This is how you might spell a better function... |
copy
parameter which defaults toFalse
.None
option to thedtype
parameter.Item #1 is inspired by situations like the one in Stack Overflow question https://stackoverflow.com/q/58998475/2988730. Sometimes, you just need to ensure a copy, and it's nice not to have to check things like
if asfarray(x) is x: x = x.copy()
.Item #2 solves the problem of trying to do
asfarray(x, dtype=x.dtype)
forx
that don't have adtype
attribute, like lists or tuples.API Change, so mailing list: https://mail.python.org/pipermail/numpy-discussion/2019-November/080251.html