-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Construct 1d array from listlike #18769
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
Changes from 1 commit
d4d02a2
0afff94
f5f3773
44eedfa
0892280
c4e635f
d0a6e48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1162,3 +1162,28 @@ def construct_1d_arraylike_from_scalar(value, length, dtype): | |
subarr.fill(value) | ||
|
||
return subarr | ||
|
||
|
||
def construct_1d_array_from_listlike(values, dtype='object'): | ||
""" | ||
Transform any list-like object in a 1-dimensional numpy array. | ||
|
||
Parameters | ||
---------- | ||
values : any iterable which has a len() | ||
dtype : dtype, default 'object' | ||
|
||
Raises | ||
------ | ||
TypeError | ||
* If `values` does not have a len() | ||
|
||
Returns | ||
------- | ||
1-dimensional numpy array of dtype "dtype" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rename this to you can also just add another function for this as well (e.g. have 1 that accepts the dtype as a required parameter ). I also don't think we are actually using dtype anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The array we return is of dtype There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are not using this, so its very confusing. I would just rather return an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Non sequitur.
... with almost perfect duplication of code, one of which perfectly generalizes the other, and without any performance gain?! I thought you liked to reduce code :-) This method builds a 1d array of type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I will explain again. We are not using the dtype argument. So just eliminate it. I don't see utility in having it. |
||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would not object to an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is: I can't think of any code path which could be hitting it. Scalar input to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not what i am asking this is a completely internal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure it does, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a raises section to the doc-string |
||
# numpy will try to interpret nested lists as further dimensions, hence | ||
# making a 1D array that contains list-likes is a bit tricky: | ||
result = np.empty(len(values), dtype=dtype) | ||
result[:] = values | ||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an asv that hits this case?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't even think there is any valid code path that hits this case... which indeed should be suppressed in #18626
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is not valid code, then let's remove it. or make a new issue. inside a PR doesn't help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#18819
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the issue number here with a TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(done)