Skip to content

Commit 80ea044

Browse files
committed
some fixes
1 parent 5e27207 commit 80ea044

File tree

9 files changed

+40
-32
lines changed

9 files changed

+40
-32
lines changed

python/pyarrow/compute.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ def top_k_unstable(values, k, sort_keys=None, *, memory_pool=None):
609609
sort_keys.append(("dummy", "descending"))
610610
else:
611611
sort_keys = map(lambda key_name: (key_name, "descending"), sort_keys)
612-
options = SelectKOptions(k, sort_keys) # type: ignore
612+
assert isinstance(sort_keys, (map, list, tuple))
613+
options = SelectKOptions(k, sort_keys)
613614
return call_function("select_k_unstable", [values], options, memory_pool)
614615

615616

@@ -656,7 +657,8 @@ def bottom_k_unstable(values, k, sort_keys=None, *, memory_pool=None):
656657
sort_keys.append(("dummy", "ascending"))
657658
else:
658659
sort_keys = map(lambda key_name: (key_name, "ascending"), sort_keys)
659-
options = SelectKOptions(k, sort_keys) # type: ignore
660+
assert isinstance(sort_keys, (map, list, tuple))
661+
options = SelectKOptions(k, sort_keys)
660662
return call_function("select_k_unstable", [values], options, memory_pool)
661663

662664

@@ -682,7 +684,8 @@ def random(n, *, initializer='system', options=None, memory_pool=None):
682684
memory_pool : pyarrow.MemoryPool, optional
683685
If not passed, will allocate memory from the default memory pool.
684686
"""
685-
options = RandomOptions(initializer=initializer) # type: ignore
687+
options = RandomOptions(
688+
initializer=initializer) # type: ignore[reportArgumentType]
686689
return call_function("random", [], options, memory_pool, length=n)
687690

688691

python/pyarrow/dataset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
get_partition_keys as _get_partition_keys, # keep for backwards compatibility
5555
_filesystemdataset_write,
5656
)
57+
from pyarrow.fs import FileInfo
58+
59+
5760
except ImportError as exc:
5861
raise ImportError(
5962
f"The pyarrow installation is not built with support for 'dataset' ({str(exc)})"
@@ -429,6 +432,7 @@ def _ensure_single_source(path, filesystem=None):
429432

430433
# retrieve the file descriptor
431434
file_info = filesystem.get_file_info(path)
435+
assert isinstance(file_info, FileInfo)
432436

433437
# depending on the path type either return with a recursive
434438
# directory selector or as a list containing a single file

python/pyarrow/pandas_compat.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ def get_logical_type(arrow_type):
9292
def get_numpy_logical_type_map():
9393
global _numpy_logical_type_map # noqa: F824
9494
if not _numpy_logical_type_map:
95-
_numpy_logical_type_map.update({ # type: ignore[arg-type]
96-
np.bool_: 'bool', # type: ignore
97-
np.int8: 'int8', # type: ignore
98-
np.int16: 'int16', # type: ignore
99-
np.int32: 'int32', # type: ignore
100-
np.int64: 'int64', # type: ignore
101-
np.uint8: 'uint8', # type: ignore
102-
np.uint16: 'uint16', # type: ignore
103-
np.uint32: 'uint32', # type: ignore
104-
np.uint64: 'uint64', # type: ignore
105-
np.float32: 'float32', # type: ignore
106-
np.float64: 'float64', # type: ignore
95+
_numpy_logical_type_map.update({ # type: ignore[reportCallIssue]
96+
np.bool_: 'bool',
97+
np.int8: 'int8',
98+
np.int16: 'int16',
99+
np.int32: 'int32',
100+
np.int64: 'int64',
101+
np.uint8: 'uint8',
102+
np.uint16: 'uint16',
103+
np.uint32: 'uint32',
104+
np.uint64: 'uint64',
105+
np.float32: 'float32',
106+
np.float64: 'float64',
107107
'datetime64[D]': 'date',
108-
np.str_: 'string', # type: ignore
109-
np.bytes_: 'bytes', # type: ignore
108+
np.str_: 'string',
109+
np.bytes_: 'bytes',
110110
})
111111
return _numpy_logical_type_map
112112

@@ -779,7 +779,7 @@ def make_datetimetz(unit, tz):
779779
if _pandas_api.is_v1():
780780
unit = 'ns' # ARROW-3789: Coerce date/timestamp types to datetime64[ns]
781781
tz = pa.lib.string_to_tzinfo(tz)
782-
return _pandas_api.datetimetz_type(unit, tz=tz) # type: ignore
782+
return _pandas_api.datetimetz_type(unit, tz=tz) # type: ignore[reportArgumentType]
783783

784784

785785
def table_to_dataframe(
@@ -826,7 +826,8 @@ def table_to_dataframe(
826826

827827
return df
828828
else:
829-
from pandas.core.internals import BlockManager # type: ignore
829+
from pandas.core.internals import ( # type: ignore[reportMissingImports]
830+
BlockManager)
830831
from pandas import DataFrame
831832

832833
blocks = [

python/pyarrow/tests/parquet/test_metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def test_parquet_raise_on_unset_statistics():
240240

241241
stat = meta.row_group(0).column(0).statistics
242242
assert stat is not None
243-
assert not stat.has_min_max # type: ignore[attr-defined]
244-
assert stat.max is None # type: ignore[attr-defined]
243+
assert not stat.has_min_max
244+
assert stat.max is None
245245

246246

247247
def test_statistics_convert_logical_types(tempdir):
@@ -507,6 +507,7 @@ def test_multi_dataset_metadata(tempdir):
507507
_meta.append_row_groups(meta[0])
508508

509509
# Write merged metadata-only file
510+
assert _meta is not None
510511
with open(metapath, "wb") as f:
511512
_meta.write_metadata_file(f) # type: ignore[union-attr]
512513

python/pyarrow/tests/parquet/test_pandas.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,9 @@ def test_backwards_compatible_column_metadata_handling(datadir):
464464
table = _read_table(
465465
path, columns=['a'])
466466
result = table.to_pandas()
467-
tm.assert_frame_equal(result, cast(
468-
pd.DataFrame, expected[['a']].reset_index(drop=True)))
467+
expected_df = expected[['a']].reset_index(drop=True)
468+
assert isinstance(expected_df, pd.DataFrame)
469+
tm.assert_frame_equal(result, expected_df)
469470

470471

471472
@pytest.mark.pandas
@@ -525,7 +526,7 @@ def test_pandas_categorical_roundtrip():
525526
codes = np.array([2, 0, 0, 2, 0, -1, 2], dtype='int32')
526527
categories = ['foo', 'bar', 'baz']
527528
df = pd.DataFrame({'x': pd.Categorical.from_codes(
528-
codes, categories=pd.Index(categories))}) # type: ignore[arg-type]
529+
codes, categories=categories)}) # type: ignore[arg-type]
529530

530531
buf = pa.BufferOutputStream()
531532
pq.write_table(pa.table(df), buf)

python/pyarrow/tests/strategies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def arrays(draw, type, size=None, nullable=True):
324324
datetime.timedelta(hours=offset_hours, minutes=offset_min)
325325
)
326326
except ValueError:
327-
tz = zoneinfo.ZoneInfo(ty.tz) # type: ignore[union-attr]
327+
tz = zoneinfo.ZoneInfo(str(ty.tz))
328328
value = st.datetimes(timezones=st.just(tz), min_value=min_datetime,
329329
max_value=max_datetime)
330330
elif pa.types.is_duration(ty):

python/pyarrow/tests/test_acero.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_declaration_to_reader(table_source):
9090
def test_table_source():
9191
with pytest.raises(TypeError):
9292
TableSourceNodeOptions(pa.record_batch(
93-
[pa.array([1, 2, 3])], ["a"])) # type: ignore[arg-type]
93+
[pa.array([1, 2, 3])], ["a"]))
9494

9595
table_source = TableSourceNodeOptions(None)
9696
decl = Declaration("table_source", table_source)
@@ -387,7 +387,7 @@ def test_hash_join_with_residual_filter():
387387
"left outer", left_keys="key", right_keys="key",
388388
filter_expression=(
389389
pc.equal(pc.field("a"), 5)
390-
| pc.equal(pc.field("b"), 10)) # type: ignore[arg-type]
390+
| pc.equal(pc.field("b"), 10)) # type: ignore[reportOperatorIssue]
391391
)
392392
joined = Declaration(
393393
"hashjoin", options=join_opts, inputs=[left_source, right_source])

python/pyarrow/tests/test_dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,7 +3345,7 @@ def _check_dataset(schema, expected, expected_schema=None):
33453345
# Specifying with differing field types
33463346
schema = pa.schema([('a', 'int32'), ('b', 'float64')])
33473347
dataset = ds.dataset(str(tempdir / "data.parquet"), schema=schema)
3348-
expected = pa.table([table['a'].cast(pa.int32()), # type: ignore[arg-type]
3348+
expected = pa.table([table['a'].cast('int32'), # type: ignore[arg-type]
33493349
table['b']],
33503350
names=['a', 'b'])
33513351
_check_dataset(schema, expected)
@@ -4055,13 +4055,13 @@ def test_filter_mismatching_schema(tempdir, dataset_reader):
40554055
# cast the column
40564056
filtered = dataset_reader.to_table(dataset, filter=ds.field("col") > 2)
40574057
assert filtered["col"].equals(table["col"].cast(
4058-
pa.int64()).slice(2)) # type: ignore[arg-type]
4058+
'int64').slice(2)) # type: ignore[arg-type]
40594059

40604060
fragment = list(dataset.get_fragments())[0]
40614061
filtered = dataset_reader.to_table(
40624062
fragment, filter=ds.field("col") > 2, schema=schema)
40634063
assert filtered["col"].equals(table["col"].cast(
4064-
pa.int64()).slice(2)) # type: ignore[arg-type]
4064+
'int64').slice(2)) # type: ignore[arg-type]
40654065

40664066

40674067
@pytest.mark.parquet

python/pyarrow/tests/test_flight.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
)
6464
except ImportError:
6565
flight = None # type: ignore[assignment]
66-
# type: ignore[assignment, misc]
6766
FlightClient, FlightServerBase = object, object
6867
ServerAuthHandler, ClientAuthHandler = ( # type: ignore[misc]
6968
object, object) # type: ignore[assignment]
@@ -670,7 +669,6 @@ def start_call(self, info, headers):
670669
)
671670
if auth_header:
672671
values = auth_header[0].split(b' ') if isinstance(
673-
# type: ignore[arg-type]
674672
auth_header[0], bytes) else auth_header[0].split(' ')
675673
token = ''
676674
error_message = 'Invalid credentials'

0 commit comments

Comments
 (0)