-
Notifications
You must be signed in to change notification settings - Fork 106
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
Fixing issues related to dtype=object arrays in interpolation routines #1649
Changes from 9 commits
2b3edef
80b1d8e
30626fe
380ee09
c90044a
bd73b42
600fecd
3e3ea87
16474de
b6a912a
2828057
53c7760
77e17f3
e80c43d
3b38e7f
7c5e31f
9b3f4f4
de6bc52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1111,8 +1111,8 @@ def uniform_grid_fromintv(intv_prod, shape, nodes_on_bdry=True): | |
|
||
shape = normalized_scalar_param_list(shape, intv_prod.ndim, safe_int_conv) | ||
|
||
if np.shape(nodes_on_bdry) == (): | ||
nodes_on_bdry = ([(bool(nodes_on_bdry), bool(nodes_on_bdry))] * | ||
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. There should be a type hinting for the 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 agree, but am unsure how best to do it – as I often am in Python, where there is no unambiguous "correct type". A direct version would be
That expresses fairly well the different ways the function can be called, but I reckon it looks daunting to the user. An alternative could be to define this union type separately:
This has the advantage that the type signature remains short, though it may also be less useful. And arguably, if we make a definition at all then it would be consequent to make it a dedicated class, though that seems overkill here. It is also debatable whether
more confusing than the version with To be fair, the Sphinx documentation is actually pretty clear about what the 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. Here is how I understand the nodes_on_bdry argument:
What do you think about that? :) 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. @Emvlt that's not how it currently works. Your examples should actually be written
So for example
or alternatively and IMO clearer
However, the specification can also be shortened to I'm not sure if anybody really need this flexibility just to make their user code a few characters shorter. We could use a simplified type hint and then just remark in the docs that it can also be shortened by collapsing 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 don't think we will come to a good decision here and then, let's leave the interface as it is for now. But I opened an issue to discuss the use of type hints for the future. |
||
if isinstance(nodes_on_bdry, bool): | ||
nodes_on_bdry = ([(nodes_on_bdry, nodes_on_bdry)] * | ||
intv_prod.ndim) | ||
elif intv_prod.ndim == 1 and len(nodes_on_bdry) == 2: | ||
nodes_on_bdry = [nodes_on_bdry] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,11 +278,11 @@ def normalized_nodes_on_bdry(nodes_on_bdry, length): | |
>>> normalized_nodes_on_bdry([[True, False], False, True], length=3) | ||
[(True, False), (False, False), (True, True)] | ||
""" | ||
shape = np.shape(nodes_on_bdry) | ||
if shape == (): | ||
out_list = [(bool(nodes_on_bdry), bool(nodes_on_bdry))] * length | ||
elif length == 1 and shape == (2,): | ||
out_list = [(bool(nodes_on_bdry[0]), bool(nodes_on_bdry[1]))] | ||
if isinstance(nodes_on_bdry, bool): | ||
return [(bool(nodes_on_bdry), bool(nodes_on_bdry))] * length | ||
elif (length == 1 and len(nodes_on_bdry) == 2 | ||
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. bool(nodes_on_bdry) can be replaced by nodes_on_bdry |
||
and all(isinstance(d, bool) for d in nodes_on_bdry)): | ||
return [nodes_on_bdry[0], nodes_on_bdry[1]] | ||
elif len(nodes_on_bdry) == length: | ||
out_list = [] | ||
|
||
|
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 please add a warning so the user knows the values are cast as floats?
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 in 53c7760.