File tree 3 files changed +19
-6
lines changed
3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -1126,7 +1126,7 @@ Performance improvements
1126
1126
- Performance improvement in :meth: `~arrays.ArrowExtensionArray.factorize ` (:issue: `49177 `)
1127
1127
- Performance improvement in :meth: `~arrays.ArrowExtensionArray.__setitem__ ` (:issue: `50248 `, :issue: `50632 `)
1128
1128
- Performance improvement in :class: `~arrays.ArrowExtensionArray ` comparison methods when array contains NA (:issue: `50524 `)
1129
- - Performance improvement in :meth: `~arrays.ArrowExtensionArray.to_numpy ` (:issue: `49973 `)
1129
+ - Performance improvement in :meth: `~arrays.ArrowExtensionArray.to_numpy ` (:issue: `49973 `, :issue: ` 51227 ` )
1130
1130
- Performance improvement when parsing strings to :class: `BooleanDtype ` (:issue: `50613 `)
1131
1131
- Performance improvement in :meth: `DataFrame.join ` when joining on a subset of a :class: `MultiIndex ` (:issue: `48611 `)
1132
1132
- Performance improvement for :meth: `MultiIndex.intersection ` (:issue: `48604 `)
Original file line number Diff line number Diff line change @@ -880,12 +880,15 @@ def to_numpy(
880
880
na_value = self .dtype .na_value
881
881
882
882
pa_type = self ._data .type
883
- if (
884
- is_object_dtype (dtype )
885
- or pa .types .is_timestamp (pa_type )
886
- or pa .types .is_duration (pa_type )
887
- ):
883
+ if pa .types .is_temporal (pa_type ) and not pa .types .is_date (pa_type ):
884
+ # temporal types with units and/or timezones currently
885
+ # require pandas/python scalars to pass all tests
886
+ # TODO: improve performance (this is slow)
888
887
result = np .array (list (self ), dtype = dtype )
888
+ elif is_object_dtype (dtype ) and self ._hasna :
889
+ result = np .empty (len (self ), dtype = object )
890
+ mask = ~ self .isna ()
891
+ result [mask ] = np .asarray (self [mask ]._data )
889
892
else :
890
893
result = np .asarray (self ._data , dtype = dtype )
891
894
if copy or self ._hasna :
Original file line number Diff line number Diff line change @@ -1487,6 +1487,16 @@ def test_to_numpy_with_defaults(data):
1487
1487
tm .assert_numpy_array_equal (result , expected )
1488
1488
1489
1489
1490
+ def test_to_numpy_int_with_na ():
1491
+ # GH51227: ensure to_numpy does not convert int to float
1492
+ data = [1 , None ]
1493
+ arr = pd .array (data , dtype = "int64[pyarrow]" )
1494
+ result = arr .to_numpy ()
1495
+ expected = np .array ([1 , pd .NA ], dtype = object )
1496
+ assert isinstance (result [0 ], int )
1497
+ tm .assert_numpy_array_equal (result , expected )
1498
+
1499
+
1490
1500
def test_setitem_null_slice (data ):
1491
1501
# GH50248
1492
1502
orig = data .copy ()
You can’t perform that action at this time.
0 commit comments