Skip to content

Commit fd2f4b3

Browse files
committed
COMPAT: rename isnull -> isna, notnull -> notna
existing isnull, notnull remain user facing closes #15001
1 parent 4f04d0b commit fd2f4b3

File tree

132 files changed

+926
-888
lines changed

Some content is hidden

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

132 files changed

+926
-888
lines changed

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

doc/source/api.rst

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

190-
isnull
191-
notnull
190+
isna
191+
notna
192192

193193
Top-level conversions
194194
~~~~~~~~~~~~~~~~~~~~~
@@ -271,8 +271,8 @@ Conversion
271271

272272
Series.astype
273273
Series.copy
274-
Series.isnull
275-
Series.notnull
274+
Series.isna
275+
Series.notna
276276

277277
Indexing, iteration
278278
~~~~~~~~~~~~~~~~~~~
@@ -778,8 +778,8 @@ Conversion
778778
DataFrame.astype
779779
DataFrame.convert_objects
780780
DataFrame.copy
781-
DataFrame.isnull
782-
DataFrame.notnull
781+
DataFrame.isna
782+
DataFrame.notna
783783

784784
Indexing, iteration
785785
~~~~~~~~~~~~~~~~~~~
@@ -1096,8 +1096,8 @@ Conversion
10961096

10971097
Panel.astype
10981098
Panel.copy
1099-
Panel.isnull
1100-
Panel.notnull
1099+
Panel.isna
1100+
Panel.notna
11011101

11021102
Getting and setting
11031103
~~~~~~~~~~~~~~~~~~~
@@ -1340,8 +1340,8 @@ Missing Values
13401340

13411341
Index.fillna
13421342
Index.dropna
1343-
Index.isnull
1344-
Index.notnull
1343+
Index.isna
1344+
Index.notna
13451345

13461346
Conversion
13471347
~~~~~~~~~~

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

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`

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-

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

doc/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@
233233
# https://github.com/pandas-dev/pandas/issues/16186
234234

235235
moved_api_pages = [
236-
('pandas.core.common.isnull', 'pandas.isnull'),
237-
('pandas.core.common.notnull', 'pandas.notnull'),
236+
('pandas.core.common.isnull', 'pandas.isna'),
237+
('pandas.core.common.notnull', 'pandas.notna'),
238238
('pandas.core.reshape.get_dummies', 'pandas.get_dummies'),
239239
('pandas.tools.merge.concat', 'pandas.concat'),
240240
('pandas.tools.merge.merge', 'pandas.merge'),

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

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:

doc/source/options.rst

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

doc/source/whatsnew/v0.21.0.txt

+16
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ the target. Now, a ``ValueError`` will be raised when such an input is passed in
9292
...
9393
ValueError: Cannot operate inplace if there is no assignment
9494

95+
.. _whatsnew_0210.api.na_changes:
96+
97+
NA naming Changes
98+
^^^^^^^^^^^^^^^^^
99+
100+
In orde to promote more consistency among the pandas API, we have added additional top-level
101+
functions :func:`isna` and :func:`notna` that are the same as :func:`isnull` and :func:`notnull`.
102+
The naming scheme is now more consistent with methods ``.dropna()`` and ``.fillna()``. Furthermore
103+
in all cases where ``.isnull()`` and ``.notnull()`` methods are defined, these have additional methods
104+
named ``.isna()`` and ``.notna()``, these include for classes `Categorical`,
105+
`Index`, `Series`, and `DataFrame`. (:issue:`15001`).
106+
107+
The configuration option ``mode.use_inf_as_null`` has been renamed to ``mode.use_inf_as_na`` as well.
108+
109+
We *may* deprecate the ``.isnull()`` and ``.isna()`` schemes at some point in the future.
110+
95111
.. _whatsnew_0210.api:
96112

97113
Other API Changes

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'}}

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

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)