[Pandas-dev] Question about pd.NA

Joris Van den Bossche jorisvandenbossche at gmail.com
Mon Jan 13 04:31:11 EST 2020


Hi Daniel,

Thanks for the feedback! Good question, and I think you are right. It's
easy to get the wrong idea about the behaviour due to the order of
operations:

In [21]: -1 ** 2
Out[21]: -1

In [22]: -1 ** 3
Out[22]: -1

where this is seemingly all giving the same result. But doing it correctly:

In [55]: (-1) ** 2
Out[55]: 1

In [56]: (-1) ** 3
Out[56]: -1

In [57]: (-1) ** 2.5
Out[57]: (3.061616997868383e-16+1j)

you are indeed right that this is not always -1. Also numpy shows this:

In [58]: (-1) ** np.array([2, 3, 2.5])
/home/joris/miniconda3/envs/dev/bin/ipython:1: RuntimeWarning: invalid
value encountered in power
  #!/home/joris/miniconda3/envs/dev/bin/python
Out[58]: array([ 1., -1., nan])

I opened https://github.com/pandas-dev/pandas/issues/30956 for this. We
should fix this for 1.0.0 (PRs always welcome!). It should be a relatively
easy fix in removing the special case for -1 (and only leaving it for 1).

Best,
Joris






On Mon, 13 Jan 2020 at 04:02, Daniel Saxton via Pandas-dev <
pandas-dev at python.org> wrote:

> Hi all,
>
> First off just wanted to say the new pd.NA value and enhancements to
> Boolean operations are incredibly cool new features, so congratulations on
> that. One minor question: (-1) ** pd.NA is always -1 as implemented, but
> should this also be pd.NA since the "unknown" NA value could be even or odd
> (or possibly some weird non-integer value)?
>
> Thanks,
> Daniel
>
>
> _______________________________________________
> Pandas-dev mailing list
> Pandas-dev at python.org
> https://mail.python.org/mailman/listinfo/pandas-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pandas-dev/attachments/20200113/7e2a181c/attachment.html>


More information about the Pandas-dev mailing list