__init__.py 587 B

1234567891011121314151617181920212223
  1. import numpy as np
  2. import pandas as pd
  3. def is_object_or_nan_string_dtype(dtype):
  4. """
  5. Check if string-like dtype is following NaN semantics, i.e. is object
  6. dtype or a NaN-variant of the StringDtype.
  7. """
  8. return (isinstance(dtype, np.dtype) and dtype == "object") or (
  9. dtype.na_value is np.nan
  10. )
  11. def _convert_na_value(ser, expected):
  12. if ser.dtype != object:
  13. if ser.dtype.na_value is np.nan:
  14. expected = expected.fillna(np.nan)
  15. else:
  16. # GH#18463
  17. expected = expected.fillna(pd.NA)
  18. return expected