[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Robert Kern
On Tue, Oct 19, 2021 at 8:54 PM Hongyi Zhao  wrote:

> On Wed, Oct 20, 2021 at 8:29 AM Robert Kern  wrote:
> >
> > On Tue, Oct 19, 2021 at 8:22 PM  wrote:
> >>
> >> Do I have to use it this way?
> >
> >
> > Nothing is forcing you to, but everyone else will write it as
> `dtype=bool`, not `dtype=(bool)`. `dtype=(bool)` is perfectly
> syntactically-valid Python. It's just not idiomatic, so readers of your
> code will wonder why you wrote it that way and if you meant something else
> and will have trouble reading your code.
>
> I use Emacs, and find that python-lsp-server will give the dtype=() as
> the completion result, see here [1] for more detailed discussion.
>
> [1] https://github.com/python-lsp/python-lsp-server/issues/98


Well, that's not helpful of python-lsp-server. Is it looking at our type
annotations? The annotations for `dtype=` arguments are likely quite
complicated because we accept so many different types here, but `()` is not
a great completion.

-- 
Robert Kern
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Hongyi Zhao
On Wed, Oct 20, 2021 at 8:29 AM Robert Kern  wrote:
>
> On Tue, Oct 19, 2021 at 8:22 PM  wrote:
>>
>> Do I have to use it this way?
>
>
> Nothing is forcing you to, but everyone else will write it as `dtype=bool`, 
> not `dtype=(bool)`. `dtype=(bool)` is perfectly syntactically-valid Python. 
> It's just not idiomatic, so readers of your code will wonder why you wrote it 
> that way and if you meant something else and will have trouble reading your 
> code.

I use Emacs, and find that python-lsp-server will give the dtype=() as
the completion result, see here [1] for more detailed discussion.

[1] https://github.com/python-lsp/python-lsp-server/issues/98

HZ
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Robert Kern
On Tue, Oct 19, 2021 at 8:22 PM  wrote:

> Do I have to use it this way?
>

Nothing is forcing you to, but everyone else will write it as `dtype=bool`,
not `dtype=(bool)`. `dtype=(bool)` is perfectly syntactically-valid Python.
It's just not idiomatic, so readers of your code will wonder why you wrote
it that way and if you meant something else and will have trouble reading
your code.

-- 
Robert Kern
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread hongyi . zhao
Do I have to use it this way?
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Mansour Moufid
On Tue, Oct 19, 2021 at 9:43 AM  wrote:
>
> See the following testing in IPython shell:
>
> In [6]: import numpy as np
>
> In [7]: a = np.array([1], dtype=(bool))
>
> In [8]: b = np.array([1], dtype=bool)
>
> In [9]: a
> Out[9]: array([ True])
>
> In [10]: b
> Out[10]: array([ True])
>
> It seems that dtype=(bool) and dtype=bool are both correct usages. If so, 
> which is preferable?

For a one-element tuple, add a comma:

>>> bool

>>> (bool)

>>> (bool,)
(,)
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Andras Deak
On Tue, Oct 19, 2021 at 4:07 PM  wrote:

> > You could use `dis.dis` to compare the two expressions and see that they
> compile to the same bytecode.
>
> Do you mean the following:
>

Indeed, that is exactly what I meant. You don't even need the numpy import
for that. Since `bool` and `(bool)` are compiled to the same bytecode,
numpy isn't even aware that you put parentheses around `bool` in your code.



> In [1]: import numpy as np
> In [2]: from dis import dis
> In [7]: dis('bool')
>   1   0 LOAD_NAME0 (bool)
>   2 RETURN_VALUE
>
> In [8]: dis('(bool)')
>   1   0 LOAD_NAME0 (bool)
>   2 RETURN_VALUE
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: deak.and...@gmail.com
>
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Ryan Soklaski
As he said: this is not the appropriate use for this mailing list.

On Tue, Oct 19, 2021, 10:05 AM  wrote:

> > You could use `dis.dis` to compare the two expressions and see that they
> compile to the same bytecode.
>
> Do you mean the following:
>
> In [1]: import numpy as np
> In [2]: from dis import dis
> In [7]: dis('bool')
>   1   0 LOAD_NAME0 (bool)
>   2 RETURN_VALUE
>
> In [8]: dis('(bool)')
>   1   0 LOAD_NAME0 (bool)
>   2 RETURN_VALUE
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: rsokla...@gmail.com
>
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread hongyi . zhao
> You could use `dis.dis` to compare the two expressions and see that they 
> compile to the same bytecode.

Do you mean the following:

In [1]: import numpy as np
In [2]: from dis import dis
In [7]: dis('bool')
  1   0 LOAD_NAME0 (bool)
  2 RETURN_VALUE

In [8]: dis('(bool)')
  1   0 LOAD_NAME0 (bool)
  2 RETURN_VALUE
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Benjamin Root
(something) in python is only needed if you need to change the order of
precedence or if you need to split something across 2 or more lines.
Otherwise, it has no meaning and it is extraneous.

On Tue, Oct 19, 2021 at 9:42 AM  wrote:

> See the following testing in IPython shell:
>
> In [6]: import numpy as np
>
> In [7]: a = np.array([1], dtype=(bool))
>
> In [8]: b = np.array([1], dtype=bool)
>
> In [9]: a
> Out[9]: array([ True])
>
> In [10]: b
> Out[10]: array([ True])
>
> It seems that dtype=(bool) and dtype=bool are both correct usages. If so,
> which is preferable?
>
> Regards,
> HZ
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: ben.v.r...@gmail.com
>
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: dtype=(bool) vs dtype=bool

2021-10-19 Thread Andras Deak
On Tue, Oct 19, 2021 at 3:42 PM  wrote:

> See the following testing in IPython shell:
>
> In [6]: import numpy as np
>
> In [7]: a = np.array([1], dtype=(bool))
>
> In [8]: b = np.array([1], dtype=bool)
>
> In [9]: a
> Out[9]: array([ True])
>
> In [10]: b
> Out[10]: array([ True])
>
> It seems that dtype=(bool) and dtype=bool are both correct usages. If so,
> which is preferable?
>

This is not really a numpy issue: in Python itself `(bool)` is the exact
same thing as `bool`. Superfluous parentheses are just ignored. You could
use `dis.dis` to compare the two expressions and see that they compile to
the same bytecode.
So go with `dtype=bool`.

AndrĂ¡s



> Regards,
> HZ
> ___
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: deak.and...@gmail.com
>
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com