Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cpp/src/arrow/python/inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class TypeInferrer {
Status Visit(PyObject* obj, bool* keep_going) {
++total_count_;

if (obj == Py_None || (pandas_null_sentinels_ && internal::PyFloat_IsNaN(obj))) {
if (obj == Py_None || (pandas_null_sentinels_ && internal::PandasObjectIsNull(obj))) {
++none_count_;
} else if (PyBool_Check(obj)) {
++bool_count_;
Expand Down Expand Up @@ -626,6 +626,12 @@ class TypeInferrer {
// Non-exhaustive type inference
Status InferArrowType(PyObject* obj, PyObject* mask, bool pandas_null_sentinels,
std::shared_ptr<DataType>* out_type) {
if (pandas_null_sentinels) {
// ARROW-842: If pandas is not installed then null checks will be less
// comprehensive, but that is okay.
internal::InitPandasStaticData();
}

TypeInferrer inferrer(pandas_null_sentinels);
RETURN_NOT_OK(inferrer.VisitSequence(obj, mask));
RETURN_NOT_OK(inferrer.GetType(out_type));
Expand Down
10 changes: 7 additions & 3 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,17 +1205,21 @@ def test_date_objects_typed(self):
tm.assert_frame_equal(table_pandas_objects,
expected_pandas_objects)

def test_object_null_values(self):
def test_pandas_null_values(self):
# ARROW-842
NA = getattr(pd, 'NA', None)
values = np.array([datetime(2000, 1, 1), pd.NaT, NA], dtype=object)
pd_NA = getattr(pd, 'NA', None)
values = np.array([datetime(2000, 1, 1), pd.NaT, pd_NA], dtype=object)
values_with_none = np.array([datetime(2000, 1, 1), None, None],
dtype=object)
result = pa.array(values, from_pandas=True)
expected = pa.array(values_with_none, from_pandas=True)
assert result.equals(expected)
assert result.null_count == 2

# ARROW-9407
assert pa.array([pd.NaT], from_pandas=True).type == pa.null()
assert pa.array([pd_NA], from_pandas=True).type == pa.null()

def test_dates_from_integers(self):
t1 = pa.date32()
t2 = pa.date64()
Expand Down