Skip to content

Commit 4156718

Browse files
use commong function in IntDtype from_arrow
1 parent d39b8a3 commit 4156718

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

pandas/core/arrays/_arrow_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def pyarrow_array_to_numpy_and_mask(arr, dtype):
3434
a boolean mask (validity mask, so False means missing)
3535
"""
3636
buflist = arr.buffers()
37-
data = np.frombuffer(buflist[-1], dtype=dtype)[arr.offset : arr.offset + len(arr)]
37+
data = np.frombuffer(buflist[1], dtype=dtype)[arr.offset : arr.offset + len(arr)]
3838
bitmask = buflist[0]
3939
if bitmask is not None:
4040
mask = pyarrow.BooleanArray.from_buffers(

pandas/core/arrays/integer.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from pandas.core import nanops, ops
2929
from pandas.core.algorithms import take
3030
from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
31+
from pandas.core.arrays._arrow_utils import pyarrow_array_to_numpy_and_mask
3132
import pandas.core.common as com
3233
from pandas.core.indexers import check_bool_array_indexer
3334
from pandas.core.ops import invalid_comparison
@@ -103,18 +104,7 @@ def __from_arrow__(self, array):
103104

104105
results = []
105106
for arr in chunks:
106-
buflist = arr.buffers()
107-
data = np.frombuffer(buflist[1], dtype=self.type)[
108-
arr.offset : arr.offset + len(arr)
109-
]
110-
bitmask = buflist[0]
111-
if bitmask is not None:
112-
mask = pyarrow.BooleanArray.from_buffers(
113-
pyarrow.bool_(), len(arr), [None, bitmask]
114-
)
115-
mask = np.asarray(mask)
116-
else:
117-
mask = np.ones(len(arr), dtype=bool)
107+
data, mask = pyarrow_array_to_numpy_and_mask(arr, dtype=self.type)
118108
int_arr = IntegerArray(data.copy(), ~mask, copy=False)
119109
results.append(int_arr)
120110

0 commit comments

Comments
 (0)