diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index de1fb0ec5d4d55..7183eb502ce5e3 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -1322,16 +1322,12 @@ def to_numpy( copy = False if pa.types.is_timestamp(pa_type) or pa.types.is_duration(pa_type): - result = data._maybe_convert_datelike_array() - if (pa.types.is_timestamp(pa_type) and pa_type.tz is not None) or ( - dtype is not None and dtype.kind == "O" - ): - dtype = object - else: - # GH 55997 - dtype = None - na_value = pa_type.to_pandas_dtype().type("nat", pa_type.unit) - result = result.to_numpy(dtype=dtype, na_value=na_value) + # GH 55997 + if dtype != object and na_value is self.dtype.na_value: + na_value = lib.no_default + result = data._maybe_convert_datelike_array().to_numpy( + dtype=dtype, na_value=na_value + ) elif pa.types.is_time(pa_type) or pa.types.is_date(pa_type): # convert to list of python datetime.time objects before # wrapping in ndarray diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 28ee5446d4b5c1..7d87c366f05668 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -3030,7 +3030,10 @@ def test_to_numpy_temporal(pa_type, dtype): value = pd.Timestamp(1, unit=pa_type.unit, tz=pa_type.tz).as_unit(pa_type.unit) if dtype == object or (pa.types.is_timestamp(pa_type) and pa_type.tz is not None): - na = pd.NA + if dtype == object: + na = pd.NA + else: + na = pd.NaT expected = np.array([value, na], dtype=object) assert result[0].unit == value.unit else: @@ -3142,3 +3145,11 @@ def test_string_to_time_parsing_cast(): ArrowExtensionArray(pa.array([time(11, 41, 43, 76160)], from_pandas=True)) ) tm.assert_series_equal(result, expected) + + +def test_to_numpy_timestamp_to_int(): + # GH 55997 + ser = pd.Series(["2020-01-01 04:30:00"], dtype="timestamp[ns][pyarrow]") + result = ser.to_numpy(dtype=np.int64) + expected = np.array([1577853000000000000]) + tm.assert_numpy_array_equal(result, expected)