Skip to content

Commit 8298c76

Browse files
rokpaddyroddy
andcommitted
GH-9: [Python] Fix non-subscriptable error (#32)
* fix: The type parameter of array should be covariant (apache#253) * release 20.0.0.20250716 (apache#254) * Add py.typed file to signify that the library is typed See the relevant PEP https://peps.python.org/pep-0561 * Prepare `pyarrow-stubs` for history merging MINOR: [Python] Prepare `pyarrow-stubs` for history merging Co-authored-by: ZhengYu, Xu <zen-xu@outlook.com> * Add `ty` configuration and suppress error codes * One line per rule * Add licence header from original repo for all `.pyi` files * Revert "Add licence header from original repo for all `.pyi` files" This reverts commit 1631f39. * Prepare for licence merging * Exclude `stubs` from `rat` test * Add Apache licence clause to `py.typed` * Reduce list * Add `ty` as a step in the action * Run in the correct directory * Remove `check` from `pip` * Fix `unresolved-reference` error * Revert "Fix `unresolved-reference` error" This reverts commit 7ee3d2f. * Fix non-subscriptable issues --------- Co-authored-by: Patrick J. Roddy <patrickjamesroddy@gmail.com>
1 parent e69c7f5 commit 8298c76

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

python/pyarrow/pandas_compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ def _reconstruct_block(item, columns=None, extension_columns=None, return_block=
755755
# create ExtensionBlock
756756
arr = item['py_array']
757757
assert len(placement) == 1
758-
name = columns[placement[0]]
759-
pandas_dtype = extension_columns[name]
758+
name = columns.get(placement[0], None)
759+
pandas_dtype = extension_columns.get(name, None)
760760
if not hasattr(pandas_dtype, '__from_arrow__'):
761761
raise ValueError("This column does not support to be converted "
762762
"to a pandas ExtensionArray")

python/pyarrow/tests/test_cuda_numba_interop.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def teardown_module(module):
4949
@pytest.mark.parametrize("c", range(len(context_choice_ids)),
5050
ids=context_choice_ids)
5151
def test_context(c):
52-
ctx, nb_ctx = context_choices[c]
52+
ctx, nb_ctx = context_choices.get(c, (None, None))
5353
assert ctx.handle == nb_ctx.handle.value
5454
assert ctx.handle == ctx.to_numba().handle.value
5555
ctx2 = cuda.Context.from_numba(nb_ctx)
@@ -83,7 +83,7 @@ def make_random_buffer(size, target='host', dtype='uint8', ctx=None):
8383
@pytest.mark.parametrize("dtype", dtypes, ids=dtypes)
8484
@pytest.mark.parametrize("size", [0, 1, 8, 1000])
8585
def test_from_object(c, dtype, size):
86-
ctx, nb_ctx = context_choices[c]
86+
ctx, nb_ctx = context_choices.get(c, (None, None))
8787
arr, cbuf = make_random_buffer(size, target='device', dtype=dtype, ctx=ctx)
8888

8989
# Creating device buffer from numba DeviceNDArray:
@@ -161,7 +161,7 @@ def __cuda_array_interface__(self):
161161
ids=context_choice_ids)
162162
@pytest.mark.parametrize("dtype", dtypes, ids=dtypes)
163163
def test_numba_memalloc(c, dtype):
164-
ctx, nb_ctx = context_choices[c]
164+
ctx, nb_ctx = context_choices.get(c, (None, None))
165165
dtype = np.dtype(dtype)
166166
# Allocate memory using numba context
167167
# Warning: this will not be reflected in pyarrow context manager
@@ -184,7 +184,7 @@ def test_numba_memalloc(c, dtype):
184184
ids=context_choice_ids)
185185
@pytest.mark.parametrize("dtype", dtypes, ids=dtypes)
186186
def test_pyarrow_memalloc(c, dtype):
187-
ctx, nb_ctx = context_choices[c]
187+
ctx, nb_ctx = context_choices.get(c, (None, None))
188188
size = 10
189189
arr, cbuf = make_random_buffer(size, target='device', dtype=dtype, ctx=ctx)
190190

@@ -198,7 +198,7 @@ def test_pyarrow_memalloc(c, dtype):
198198
ids=context_choice_ids)
199199
@pytest.mark.parametrize("dtype", dtypes, ids=dtypes)
200200
def test_numba_context(c, dtype):
201-
ctx, nb_ctx = context_choices[c]
201+
ctx, nb_ctx = context_choices.get(c, (None, None))
202202
size = 10
203203
with nb_cuda.gpus[0]:
204204
arr, cbuf = make_random_buffer(size, target='device',
@@ -217,7 +217,7 @@ def test_numba_context(c, dtype):
217217
ids=context_choice_ids)
218218
@pytest.mark.parametrize("dtype", dtypes, ids=dtypes)
219219
def test_pyarrow_jit(c, dtype):
220-
ctx, nb_ctx = context_choices[c]
220+
ctx, nb_ctx = context_choices.get(c, (None, None))
221221

222222
@nb_cuda.jit
223223
def increment_by_one(an_array):

python/pyarrow/tests/test_gdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def select_frame(self, func_name):
159159
if m is None:
160160
pytest.fail(f"Could not select frame for function {func_name}")
161161

162-
frame_num = int(m[1])
162+
frame_num = int(m.get(1, None))
163163
out = self.run_command(f"frame {frame_num}")
164164
assert f"in {func_name}" in out
165165

python/stubs/__lib_pxi/array.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,7 @@ class Array(_PandasConvertible[pd.Series], Generic[_Scalar_co]):
19921992
def __getitem__(self, key: int) -> _Scalar_co: ...
19931993
@overload
19941994
def __getitem__(self, key: builtins.slice) -> Self: ...
1995+
def __getitem__(self, key):
19951996
"""
19961997
Slice or return value at given index
19971998

0 commit comments

Comments
 (0)