diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 34b149a6b8261..58eb83b7d57ae 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -89,7 +89,7 @@ Indexing Missing ^^^^^^^ -- +- Fixed bug where object with no data attribute were not being caught (:issue:`27482`) - - diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 6f599a6be6021..982347de69b1e 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -2,7 +2,6 @@ missing types & inference """ import numpy as np - from pandas._config import get_option from pandas._libs import lib @@ -46,7 +45,6 @@ isposinf_scalar = libmissing.isposinf_scalar isneginf_scalar = libmissing.isneginf_scalar - def isna(obj): """ Detect missing values for an array-like object. @@ -128,6 +126,12 @@ def isna(obj): def _isna_new(obj): + try: + # If any object doesn't have an attribute data + if obj._data == None: + return False + except: + pass if is_scalar(obj): return libmissing.checknull(obj) # hack (for now) because MI registers as ndarray @@ -152,6 +156,7 @@ def _isna_new(obj): elif hasattr(obj, "__array__"): return _isna_ndarraylike(np.asarray(obj)) else: + print("Test") return obj is None @@ -222,8 +227,10 @@ def _isna_ndarraylike(obj): else: values = obj + dtype = values.dtype + if is_extension: if isinstance(obj, (ABCIndexClass, ABCSeries)): values = obj._values @@ -254,7 +261,6 @@ def _isna_ndarraylike(obj): # box if isinstance(obj, ABCSeries): result = obj._constructor(result, index=obj.index, name=obj.name, copy=False) - return result diff --git a/scripts/tests/test_27482.py b/scripts/tests/test_27482.py new file mode 100644 index 0000000000000..e3b637728505b --- /dev/null +++ b/scripts/tests/test_27482.py @@ -0,0 +1,19 @@ +import pandas as pd +import pytest +import unittest + +class TestStringMethods(unittest.TestCase): + + def test1(self): + x = pd.Series([1,2,3,4]) + xt = type(x) + assert pd.isnull(xt)==False,"Passed" + + def test2(self): + y = pd.DataFrame({"col": [1,2,3,4]}) + yt = type(y) + assert pd.isnull(yt)==False,"Passed" + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file