Skip to content

Commit 7930202

Browse files
authored
COMPAT: rename isnull -> isna, notnull -> notna (#16972)
closes #15001
1 parent 395f712 commit 7930202

File tree

134 files changed

+1003
-898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1003
-898
lines changed

Diff for: doc/source/10min.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ To get the boolean mask where values are ``nan``
373373

374374
.. ipython:: python
375375
376-
pd.isnull(df1)
376+
pd.isna(df1)
377377
378378
379379
Operations

Diff for: doc/source/api.rst

+10-8
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ Top-level missing data
187187
.. autosummary::
188188
:toctree: generated/
189189

190+
isna
190191
isnull
192+
notna
191193
notnull
192194

193195
Top-level conversions
@@ -272,8 +274,8 @@ Conversion
272274
Series.astype
273275
Series.infer_objects
274276
Series.copy
275-
Series.isnull
276-
Series.notnull
277+
Series.isna
278+
Series.notna
277279

278280
Indexing, iteration
279281
~~~~~~~~~~~~~~~~~~~
@@ -781,8 +783,8 @@ Conversion
781783
DataFrame.convert_objects
782784
DataFrame.infer_objects
783785
DataFrame.copy
784-
DataFrame.isnull
785-
DataFrame.notnull
786+
DataFrame.isna
787+
DataFrame.notna
786788

787789
Indexing, iteration
788790
~~~~~~~~~~~~~~~~~~~
@@ -1099,8 +1101,8 @@ Conversion
10991101

11001102
Panel.astype
11011103
Panel.copy
1102-
Panel.isnull
1103-
Panel.notnull
1104+
Panel.isna
1105+
Panel.notna
11041106

11051107
Getting and setting
11061108
~~~~~~~~~~~~~~~~~~~
@@ -1343,8 +1345,8 @@ Missing Values
13431345

13441346
Index.fillna
13451347
Index.dropna
1346-
Index.isnull
1347-
Index.notnull
1348+
Index.isna
1349+
Index.notna
13481350

13491351
Conversion
13501352
~~~~~~~~~~

Diff for: doc/source/basics.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ So, for instance, to reproduce :meth:`~DataFrame.combine_first` as above:
444444

445445
.. ipython:: python
446446
447-
combiner = lambda x, y: np.where(pd.isnull(x), y, x)
447+
combiner = lambda x, y: np.where(pd.isna(x), y, x)
448448
df1.combine(df2, combiner)
449449
450450
.. _basics.stats:
@@ -511,7 +511,7 @@ optional ``level`` parameter which applies only if the object has a
511511
:header: "Function", "Description"
512512
:widths: 20, 80
513513

514-
``count``, Number of non-null observations
514+
``count``, Number of non-na observations
515515
``sum``, Sum of values
516516
``mean``, Mean of values
517517
``mad``, Mean absolute deviation
@@ -541,7 +541,7 @@ will exclude NAs on Series input by default:
541541
np.mean(df['one'].values)
542542
543543
``Series`` also has a method :meth:`~Series.nunique` which will return the
544-
number of unique non-null values:
544+
number of unique non-na values:
545545

546546
.. ipython:: python
547547

Diff for: doc/source/categorical.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,14 @@ a code of ``-1``.
863863
s.cat.codes
864864
865865
866-
Methods for working with missing data, e.g. :meth:`~Series.isnull`, :meth:`~Series.fillna`,
866+
Methods for working with missing data, e.g. :meth:`~Series.isna`, :meth:`~Series.fillna`,
867867
:meth:`~Series.dropna`, all work normally:
868868

869869
.. ipython:: python
870870
871871
s = pd.Series(["a", "b", np.nan], dtype="category")
872872
s
873-
pd.isnull(s)
873+
pd.isna(s)
874874
s.fillna("a")
875875
876876
Differences to R's `factor`

Diff for: doc/source/comparison_with_sas.rst

+5-6
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ For example, in SAS you could do this to filter missing values.
444444
if value_x ^= .;
445445
run;
446446
447-
Which doesn't work in in pandas. Instead, the ``pd.isnull`` or ``pd.notnull`` functions
447+
Which doesn't work in in pandas. Instead, the ``pd.isna`` or ``pd.notna`` functions
448448
should be used for comparisons.
449449

450450
.. ipython:: python
451451
452-
outer_join[pd.isnull(outer_join['value_x'])]
453-
outer_join[pd.notnull(outer_join['value_x'])]
452+
outer_join[pd.isna(outer_join['value_x'])]
453+
outer_join[pd.notna(outer_join['value_x'])]
454454
455455
pandas also provides a variety of methods to work with missing data - some of
456456
which would be challenging to express in SAS. For example, there are methods to
@@ -570,15 +570,15 @@ machine's memory, but also that the operations on that data may be faster.
570570

571571
If out of core processing is needed, one possibility is the
572572
`dask.dataframe <http://dask.pydata.org/en/latest/dataframe.html>`_
573-
library (currently in development) which
573+
library (currently in development) which
574574
provides a subset of pandas functionality for an on-disk ``DataFrame``
575575

576576
Data Interop
577577
~~~~~~~~~~~~
578578

579579
pandas provides a :func:`read_sas` method that can read SAS data saved in
580580
the XPORT or SAS7BDAT binary format.
581-
581+
582582
.. code-block:: none
583583
584584
libname xportout xport 'transport-file.xpt';
@@ -613,4 +613,3 @@ to interop data between SAS and pandas is to serialize to csv.
613613
614614
In [9]: %time df = pd.read_csv('big.csv')
615615
Wall time: 4.86 s
616-

Diff for: doc/source/comparison_with_sql.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Just like SQL's OR and AND, multiple conditions can be passed to a DataFrame usi
101101
# tips by parties of at least 5 diners OR bill total was more than $45
102102
tips[(tips['size'] >= 5) | (tips['total_bill'] > 45)]
103103
104-
NULL checking is done using the :meth:`~pandas.Series.notnull` and :meth:`~pandas.Series.isnull`
104+
NULL checking is done using the :meth:`~pandas.Series.notna` and :meth:`~pandas.Series.isna`
105105
methods.
106106

107107
.. ipython:: python
@@ -121,9 +121,9 @@ where ``col2`` IS NULL with the following query:
121121
122122
.. ipython:: python
123123
124-
frame[frame['col2'].isnull()]
124+
frame[frame['col2'].isna()]
125125
126-
Getting items where ``col1`` IS NOT NULL can be done with :meth:`~pandas.Series.notnull`.
126+
Getting items where ``col1`` IS NOT NULL can be done with :meth:`~pandas.Series.notna`.
127127

128128
.. code-block:: sql
129129
@@ -133,7 +133,7 @@ Getting items where ``col1`` IS NOT NULL can be done with :meth:`~pandas.Series.
133133
134134
.. ipython:: python
135135
136-
frame[frame['col1'].notnull()]
136+
frame[frame['col1'].notna()]
137137
138138
139139
GROUP BY

Diff for: doc/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@
238238
# https://github.com/pandas-dev/pandas/issues/16186
239239

240240
moved_api_pages = [
241-
('pandas.core.common.isnull', 'pandas.isnull'),
242-
('pandas.core.common.notnull', 'pandas.notnull'),
241+
('pandas.core.common.isnull', 'pandas.isna'),
242+
('pandas.core.common.notnull', 'pandas.notna'),
243243
('pandas.core.reshape.get_dummies', 'pandas.get_dummies'),
244244
('pandas.tools.merge.concat', 'pandas.concat'),
245245
('pandas.tools.merge.merge', 'pandas.merge'),

Diff for: doc/source/gotchas.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ For many reasons we chose the latter. After years of production use it has
202202
proven, at least in my opinion, to be the best decision given the state of
203203
affairs in NumPy and Python in general. The special value ``NaN``
204204
(Not-A-Number) is used everywhere as the ``NA`` value, and there are API
205-
functions ``isnull`` and ``notnull`` which can be used across the dtypes to
205+
functions ``isna`` and ``notna`` which can be used across the dtypes to
206206
detect NA values.
207207

208208
However, it comes with it a couple of trade-offs which I most certainly have

Diff for: doc/source/missing_data.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ When / why does data become missing?
3636
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3737

3838
Some might quibble over our usage of *missing*. By "missing" we simply mean
39-
**null** or "not present for whatever reason". Many data sets simply arrive with
39+
**na** or "not present for whatever reason". Many data sets simply arrive with
4040
missing data, either because it exists and was not collected or it never
4141
existed. For example, in a collection of financial time series, some of the time
4242
series might start on different dates. Thus, values prior to the start date
@@ -63,27 +63,27 @@ to handling missing data. While ``NaN`` is the default missing value marker for
6363
reasons of computational speed and convenience, we need to be able to easily
6464
detect this value with data of different types: floating point, integer,
6565
boolean, and general object. In many cases, however, the Python ``None`` will
66-
arise and we wish to also consider that "missing" or "null".
66+
arise and we wish to also consider that "missing" or "na".
6767

6868
.. note::
6969

7070
Prior to version v0.10.0 ``inf`` and ``-inf`` were also
71-
considered to be "null" in computations. This is no longer the case by
72-
default; use the ``mode.use_inf_as_null`` option to recover it.
71+
considered to be "na" in computations. This is no longer the case by
72+
default; use the ``mode.use_inf_as_na`` option to recover it.
7373

74-
.. _missing.isnull:
74+
.. _missing.isna:
7575

7676
To make detecting missing values easier (and across different array dtypes),
77-
pandas provides the :func:`~pandas.core.common.isnull` and
78-
:func:`~pandas.core.common.notnull` functions, which are also methods on
77+
pandas provides the :func:`isna` and
78+
:func:`notna` functions, which are also methods on
7979
``Series`` and ``DataFrame`` objects:
8080

8181
.. ipython:: python
8282
8383
df2['one']
84-
pd.isnull(df2['one'])
85-
df2['four'].notnull()
86-
df2.isnull()
84+
pd.isna(df2['one'])
85+
df2['four'].notna()
86+
df2.isna()
8787
8888
.. warning::
8989

@@ -206,7 +206,7 @@ with missing data.
206206
Filling missing values: fillna
207207
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208208

209-
The **fillna** function can "fill in" NA values with non-null data in a couple
209+
The **fillna** function can "fill in" NA values with non-na data in a couple
210210
of ways, which we illustrate:
211211

212212
**Replace NA with a scalar value**
@@ -220,7 +220,7 @@ of ways, which we illustrate:
220220
**Fill gaps forward or backward**
221221

222222
Using the same filling arguments as :ref:`reindexing <basics.reindexing>`, we
223-
can propagate non-null values forward or backward:
223+
can propagate non-na values forward or backward:
224224

225225
.. ipython:: python
226226
@@ -288,7 +288,7 @@ a Series in this case.
288288

289289
.. ipython:: python
290290
291-
dff.where(pd.notnull(dff), dff.mean(), axis='columns')
291+
dff.where(pd.notna(dff), dff.mean(), axis='columns')
292292
293293
294294
.. _missing_data.dropna:

Diff for: doc/source/options.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ mode.chained_assignment warn Raise an exception, warn, or no
419419
assignment, The default is warn
420420
mode.sim_interactive False Whether to simulate interactive mode
421421
for purposes of testing.
422-
mode.use_inf_as_null False True means treat None, NaN, -INF,
423-
INF as null (old way), False means
422+
mode.use_inf_as_na False True means treat None, NaN, -INF,
423+
INF as NA (old way), False means
424424
None and NaN are null, but INF, -INF
425-
are not null (new way).
425+
are not NA (new way).
426426
compute.use_bottleneck True Use the bottleneck library to accelerate
427427
computation if it is installed.
428428
compute.use_numexpr True Use the numexpr library to accelerate

Diff for: doc/source/whatsnew/v0.21.0.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ the target. Now, a ``ValueError`` will be raised when such an input is passed in
128128
...
129129
ValueError: Cannot operate inplace if there is no assignment
130130

131-
.. _whatsnew_0210.dtype_conversions:
132-
133131
Dtype Conversions
134132
^^^^^^^^^^^^^^^^^
135133

@@ -187,6 +185,20 @@ Dtype Conversions
187185
- Inconsistent behavior in ``.where()`` with datetimelikes which would raise rather than coerce to ``object`` (:issue:`16402`)
188186
- Bug in assignment against ``int64`` data with ``np.ndarray`` with ``float64`` dtype may keep ``int64`` dtype (:issue:`14001`)
189187

188+
.. _whatsnew_0210.api.na_changes:
189+
190+
NA naming Changes
191+
^^^^^^^^^^^^^^^^^
192+
193+
In orde to promote more consistency among the pandas API, we have added additional top-level
194+
functions :func:`isna` and :func:`notna` that are aliases for :func:`isnull` and :func:`notnull`.
195+
The naming scheme is now more consistent with methods like ``.dropna()`` and ``.fillna()``. Furthermore
196+
in all cases where ``.isnull()`` and ``.notnull()`` methods are defined, these have additional methods
197+
named ``.isna()`` and ``.notna()``, these are included for classes ``Categorical``,
198+
``Index``, ``Series``, and ``DataFrame``. (:issue:`15001`).
199+
200+
The configuration option ``mode.use_inf_as_null``is deprecated, and ``mode.use_inf_as_na`` is added as a replacement.
201+
190202
.. _whatsnew_0210.api:
191203

192204
Other API Changes

Diff for: pandas/_libs/algos_rank_helper.pxi.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def rank_1d_{{dtype}}(object in_arr, ties_method='average', ascending=True,
8383
nan_value = {{neg_nan_value}}
8484

8585
{{if dtype == 'object'}}
86-
mask = lib.isnullobj(values)
86+
mask = lib.isnaobj(values)
8787
{{elif dtype == 'float64'}}
8888
mask = np.isnan(values)
8989
{{elif dtype == 'int64'}}
@@ -259,7 +259,7 @@ def rank_2d_{{dtype}}(object in_arr, axis=0, ties_method='average',
259259
nan_value = {{neg_nan_value}}
260260

261261
{{if dtype == 'object'}}
262-
mask = lib.isnullobj2d(values)
262+
mask = lib.isnaobj2d(values)
263263
{{elif dtype == 'float64'}}
264264
mask = np.isnan(values)
265265
{{elif dtype == 'int64'}}

Diff for: pandas/_libs/lib.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def item_from_zerodim(object val):
286286

287287
@cython.wraparound(False)
288288
@cython.boundscheck(False)
289-
def isnullobj(ndarray arr):
289+
def isnaobj(ndarray arr):
290290
cdef Py_ssize_t i, n
291291
cdef object val
292292
cdef ndarray[uint8_t] result
@@ -303,7 +303,7 @@ def isnullobj(ndarray arr):
303303

304304
@cython.wraparound(False)
305305
@cython.boundscheck(False)
306-
def isnullobj_old(ndarray arr):
306+
def isnaobj_old(ndarray arr):
307307
cdef Py_ssize_t i, n
308308
cdef object val
309309
cdef ndarray[uint8_t] result
@@ -320,7 +320,7 @@ def isnullobj_old(ndarray arr):
320320

321321
@cython.wraparound(False)
322322
@cython.boundscheck(False)
323-
def isnullobj2d(ndarray arr):
323+
def isnaobj2d(ndarray arr):
324324
cdef Py_ssize_t i, j, n, m
325325
cdef object val
326326
cdef ndarray[uint8_t, ndim=2] result
@@ -339,7 +339,7 @@ def isnullobj2d(ndarray arr):
339339

340340
@cython.wraparound(False)
341341
@cython.boundscheck(False)
342-
def isnullobj2d_old(ndarray arr):
342+
def isnaobj2d_old(ndarray arr):
343343
cdef Py_ssize_t i, j, n, m
344344
cdef object val
345345
cdef ndarray[uint8_t, ndim=2] result

Diff for: pandas/_libs/testing.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22

33
from pandas import compat
4-
from pandas.core.dtypes.missing import isnull, array_equivalent
4+
from pandas.core.dtypes.missing import isna, array_equivalent
55
from pandas.core.dtypes.common import is_dtype_equal
66

77
cdef NUMERIC_TYPES = (
@@ -182,7 +182,7 @@ cpdef assert_almost_equal(a, b,
182182
if a == b:
183183
# object comparison
184184
return True
185-
if isnull(a) and isnull(b):
185+
if isna(a) and isna(b):
186186
# nan / None comparison
187187
return True
188188
if is_comparable_as_number(a) and is_comparable_as_number(b):

0 commit comments

Comments
 (0)