Skip to content

Commit 2da060c

Browse files
committed
DOC: enhanced docs for #10569
1 parent 0de48d0 commit 2da060c

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

doc/source/missing_data.rst

+21-7
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,40 @@ detect this value with data of different types: floating point, integer,
6868
boolean, and general object. In many cases, however, the Python ``None`` will
6969
arise and we wish to also consider that "missing" or "null".
7070

71-
Prior to version v0.10.0 ``inf`` and ``-inf`` were also
72-
considered to be "null" in computations. This is no longer the case by
73-
default; use the ``mode.use_inf_as_null`` option to recover it.
71+
.. note::
72+
73+
Prior to version v0.10.0 ``inf`` and ``-inf`` were also
74+
considered to be "null" in computations. This is no longer the case by
75+
default; use the ``mode.use_inf_as_null`` option to recover it.
7476

7577
.. _missing.isnull:
7678

7779
To make detecting missing values easier (and across different array dtypes),
7880
pandas provides the :func:`~pandas.core.common.isnull` and
7981
:func:`~pandas.core.common.notnull` functions, which are also methods on
80-
``Series`` objects:
82+
``Series`` and ``DataFrame`` objects:
8183

8284
.. ipython:: python
8385
8486
df2['one']
8587
pd.isnull(df2['one'])
8688
df2['four'].notnull()
89+
df2.isnull()
90+
91+
.. warning::
92+
93+
One has to be mindful that in python (and numpy), the ``nan's`` don't compare equal, but ``None's`` **do**.
94+
95+
.. ipython:: python
96+
97+
None == None
98+
np.nan == np.nan
99+
100+
So as compared to above, a scalar equality comparison versus a ``None/np.nan`` doesn't provide useful information.
101+
102+
.. ipython:: python
87103
88-
**Summary:** ``NaN`` and ``None`` (in object arrays) are considered
89-
missing by the ``isnull`` and ``notnull`` functions. ``inf`` and
90-
``-inf`` are no longer considered missing by default.
104+
df2['one'] == np.nan
91105
92106
Datetimes
93107
---------

doc/source/whatsnew/v0.17.0.txt

+40-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,46 @@ or it can return False if broadcasting can not be done:
223223

224224
np.array([1, 2, 3]) == np.array([1, 2])
225225

226+
Changes to Boolean Comparisons vs. None
227+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
228+
229+
Boolean comparisons of a ``Series`` vs ``None`` will now be equivalent to comparing with ``np.nan``, rather than raise ``TypeError``. xref (:issue:`1079`).
230+
231+
.. ipython:: python
232+
233+
s = Series(range(3.))
234+
s.iloc[1] = None
235+
s
236+
237+
Previous behavior:
238+
239+
.. code-block:: python
240+
241+
In [5]: s==None
242+
TypeError: Could not compare <type 'NoneType'> type with Series
243+
244+
New behavior:
245+
246+
.. ipython:: python
247+
248+
s==None
249+
250+
Usually you simply want to know which values are null.
251+
252+
.. ipython:: python
253+
254+
s.isnull()
255+
256+
.. warning::
257+
258+
You generally will want to use ``isnull/notnull`` for these types of comparisons, as ``isnull/notnull`` tells you which elements are null. One has to be
259+
mindful that ``nan's`` don't compare equal, but ``None's`` do.
260+
261+
.. ipython:: python
262+
263+
None == None
264+
np.nan == np.nan
265+
226266
Other API Changes
227267
^^^^^^^^^^^^^^^^^
228268

@@ -285,7 +325,6 @@ Performance Improvements
285325
Bug Fixes
286326
~~~~~~~~~
287327

288-
- Boolean comparisons of a ``Series`` vs ``None`` will now be equivalent to comparing with ``np.nan``, rather than raise ``TypeError``, xref (:issue:`1079`).
289328
- Bug in ``DataFrame.apply`` when function returns categorical series. (:issue:`9573`)
290329
- Bug in ``to_datetime`` with invalid dates and formats supplied (:issue:`10154`)
291330
- Bug in ``Index.drop_duplicates`` dropping name(s) (:issue:`10115`)

0 commit comments

Comments
 (0)