@@ -352,9 +352,7 @@ def _from_sequence_of_strings(
352352 from pandas .core .tools .datetimes import to_datetime
353353
354354 scalars = to_datetime (strings , errors = "raise" ).date
355-
356- scalars = pa .array (scalars , mask = mask .view (bool ), type = pa_type )
357-
355+ scalars = pa .array (scalars , type = pa_type , mask = mask )
358356 elif pa .types .is_duration (pa_type ):
359357 from pandas .core .tools .timedeltas import to_timedelta
360358
@@ -965,7 +963,10 @@ def __len__(self) -> int:
965963 def __contains__ (self , key ) -> bool :
966964 # https://github.com/pandas-dev/pandas/pull/51307#issuecomment-1426372604
967965 if isna (key ) and key is not self .dtype .na_value :
968- if self .dtype .kind == "f" and lib .is_float (key ):
966+ if lib .is_float (key ) and is_nan_na ():
967+ return self .dtype .na_value in self
968+ elif self .dtype .kind == "f" and lib .is_float (key ):
969+ # Check specifically for NaN
969970 return pc .any (pc .is_nan (self ._pa_array )).as_py ()
970971
971972 # e.g. date or timestamp types we do not allow None here to match pd.NA
@@ -1512,9 +1513,7 @@ def to_numpy(
15121513 na_value : object = lib .no_default ,
15131514 ) -> np .ndarray :
15141515 original_na_value = na_value
1515- dtype , na_value = to_numpy_dtype_inference (
1516- self , dtype , na_value , self ._hasna , is_pyarrow = True
1517- )
1516+ dtype , na_value = to_numpy_dtype_inference (self , dtype , na_value , self ._hasna )
15181517 pa_type = self ._pa_array .type
15191518 if not self ._hasna or isna (na_value ) or pa .types .is_null (pa_type ):
15201519 data = self
@@ -2073,7 +2072,7 @@ def __setitem__(self, key, value) -> None:
20732072 raise ValueError ("Length of indexer and values mismatch" )
20742073 chunks = [
20752074 * self ._pa_array [:key ].chunks ,
2076- pa .array ([value ], type = self ._pa_array .type ),
2075+ pa .array ([value ], type = self ._pa_array .type , from_pandas = is_nan_na () ),
20772076 * self ._pa_array [key + 1 :].chunks ,
20782077 ]
20792078 data = pa .chunked_array (chunks ).combine_chunks ()
@@ -2127,7 +2126,7 @@ def _rank_calc(
21272126 pa_type = pa .float64 ()
21282127 else :
21292128 pa_type = pa .uint64 ()
2130- result = pa .array (ranked , type = pa_type )
2129+ result = pa .array (ranked , type = pa_type , from_pandas = is_nan_na () )
21312130 return result
21322131
21332132 data = self ._pa_array .combine_chunks ()
@@ -2379,7 +2378,7 @@ def _to_numpy_and_type(value) -> tuple[np.ndarray, pa.DataType | None]:
23792378 right , right_type = _to_numpy_and_type (right )
23802379 pa_type = left_type or right_type
23812380 result = np .where (cond , left , right )
2382- return pa .array (result , type = pa_type )
2381+ return pa .array (result , type = pa_type , from_pandas = is_nan_na () )
23832382
23842383 @classmethod
23852384 def _replace_with_mask (
@@ -2423,7 +2422,7 @@ def _replace_with_mask(
24232422
24242423 result = np .array (values , dtype = object )
24252424 result [mask ] = replacements
2426- return pa .array (result , type = values .type )
2425+ return pa .array (result , type = values .type , from_pandas = is_nan_na () )
24272426
24282427 # ------------------------------------------------------------------
24292428 # GroupBy Methods
0 commit comments