Skip to content

Commit

Permalink
Add cython-lint to pre-commit checks. (#12020)
Browse files Browse the repository at this point in the history
Adds `cython-lint` (https://github.com/MarcoGorelli/cython-lint) to the list of pre-commit checks. It is most similar to flake8 but with support for Cython syntax -- the rule set it enforces is fairly short, it mostly helps identify unused imports in Cython files.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #12020
  • Loading branch information
bdice authored Oct 28, 2022
1 parent 7620fb1 commit 0603167
Show file tree
Hide file tree
Showing 49 changed files with 51 additions and 262 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ repos:
types: [file]
types_or: [python, cython]
additional_dependencies: ["flake8-force"]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.1.10
hooks:
- id: cython-lint
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.971'
hooks:
Expand Down
9 changes: 1 addition & 8 deletions python/cudf/cudf/_lib/aggregation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

from enum import Enum, IntEnum

import numba
import numpy as np
import pandas as pd

from libcpp.memory cimport unique_ptr
from libcpp.string cimport string
from libcpp.utility cimport move
from libcpp.vector cimport vector

from cudf._lib.types import (
LIBCUDF_TO_SUPPORTED_NUMPY_TYPES,
SUPPORTED_NUMPY_TO_LIBCUDF_TYPES,
NullHandling,
)
from cudf._lib.types import SUPPORTED_NUMPY_TO_LIBCUDF_TYPES, NullHandling
from cudf.utils import cudautils

from cudf._lib.types cimport (
Expand Down
3 changes: 0 additions & 3 deletions python/cudf/cudf/_lib/binaryop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

from enum import IntEnum

import numpy as np

from libcpp.memory cimport unique_ptr
from libcpp.string cimport string
from libcpp.utility cimport move

from cudf._lib.binaryop cimport underlying_type_t_binary_operator
from cudf._lib.column cimport Column

from cudf._lib.replace import replace_nulls
from cudf._lib.scalar import as_device_scalar

from cudf._lib.scalar cimport DeviceScalar
Expand Down
21 changes: 2 additions & 19 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,23 @@

import cupy as cp
import numpy as np
import pandas as pd

import rmm

import cudf
import cudf._lib as libcudf
from cudf.api.types import is_categorical_dtype, is_list_dtype, is_struct_dtype
from cudf.api.types import is_categorical_dtype
from cudf.core.buffer import Buffer, DeviceBufferLike, as_device_buffer_like

from cpython.buffer cimport PyObject_CheckBuffer
from libc.stdint cimport uintptr_t
from libcpp cimport bool
from libcpp.memory cimport make_unique, unique_ptr
from libcpp.pair cimport pair
from libcpp.utility cimport move
from libcpp.vector cimport vector

from rmm._lib.device_buffer cimport DeviceBuffer

from cudf._lib.cpp.strings.convert.convert_integers cimport (
from_integers as cpp_from_integers,
)

from cudf._lib.types import (
LIBCUDF_TO_SUPPORTED_NUMPY_TYPES,
SUPPORTED_NUMPY_TO_LIBCUDF_TYPES,
)

from cudf._lib.types cimport (
dtype_from_column_view,
dtype_to_data_type,
underlying_type_t_type_id,
)
from cudf._lib.types cimport dtype_from_column_view, dtype_to_data_type

from cudf._lib.null_mask import bitmask_allocation_size_bytes

Expand All @@ -46,7 +30,6 @@ from cudf._lib.cpp.column.column_factories cimport (
make_numeric_column,
)
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.lists.lists_column_view cimport lists_column_view
from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.scalar cimport DeviceScalar

Expand Down
5 changes: 1 addition & 4 deletions python/cudf/cudf/_lib/copying.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import pickle
import warnings

import pandas as pd

from libc.stdint cimport int32_t, int64_t, uint8_t, uintptr_t
from libc.stdint cimport int32_t, uint8_t, uintptr_t
from libcpp cimport bool
from libcpp.memory cimport make_shared, make_unique, shared_ptr, unique_ptr
from libcpp.utility cimport move
Expand Down Expand Up @@ -42,7 +40,6 @@ from cudf._lib.utils cimport (
columns_from_table_view,
columns_from_unique_ptr,
data_from_table_view,
data_from_unique_ptr,
table_view_from_columns,
)

Expand Down
12 changes: 3 additions & 9 deletions python/cudf/cudf/_lib/csv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from libcpp cimport bool
from libcpp.map cimport map
from libcpp.memory cimport make_unique, unique_ptr
from libcpp.memory cimport unique_ptr
from libcpp.string cimport string
from libcpp.utility cimport move
from libcpp.vector cimport vector

cimport cudf._lib.cpp.types as libcudf_types
from cudf._lib.cpp.types cimport data_type, type_id
from cudf._lib.cpp.types cimport data_type
from cudf._lib.io.datasource cimport Datasource, NativeFileDatasource
from cudf._lib.types cimport dtype_to_data_type

Expand Down Expand Up @@ -45,11 +45,7 @@ from cudf._lib.cpp.io.types cimport (
)
from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.io.utils cimport make_sink_info, make_source_info
from cudf._lib.utils cimport (
data_from_unique_ptr,
table_view_from_columns,
table_view_from_table,
)
from cudf._lib.utils cimport data_from_unique_ptr, table_view_from_table

from pyarrow.lib import NativeFile

Expand Down Expand Up @@ -121,8 +117,6 @@ cdef csv_reader_options make_csv_reader_options(
) except *:
cdef source_info c_source_info = make_source_info([datasource])
cdef compression_type c_compression
cdef size_type c_header
cdef string c_prefix
cdef vector[string] c_names
cdef size_t c_byte_range_offset = (
byte_range[0] if byte_range is not None else 0
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/expressions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from enum import Enum
from cython.operator cimport dereference
from libc.stdint cimport int64_t
from libcpp.memory cimport make_unique, unique_ptr
from libcpp.utility cimport move

from cudf._lib.cpp cimport expressions as libcudf_exp
from cudf._lib.cpp.types cimport size_type
Expand Down
10 changes: 1 addition & 9 deletions python/cudf/cudf/_lib/filling.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

import numpy as np

from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

Expand All @@ -15,11 +12,7 @@ from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.cpp.types cimport size_type
from cudf._lib.scalar cimport DeviceScalar
from cudf._lib.utils cimport (
columns_from_unique_ptr,
data_from_unique_ptr,
table_view_from_columns,
)
from cudf._lib.utils cimport columns_from_unique_ptr, table_view_from_columns


def fill_in_place(Column destination, int begin, int end, DeviceScalar value):
Expand Down Expand Up @@ -64,7 +57,6 @@ def repeat(list inp, object count):
def _repeat_via_column(list inp, Column count):
cdef table_view c_inp = table_view_from_columns(inp)
cdef column_view c_count = count.view()
cdef bool c_check_count = False
cdef unique_ptr[table] c_result

with nogil:
Expand Down
16 changes: 1 addition & 15 deletions python/cudf/cudf/_lib/groupby.pyx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

from collections import defaultdict

import numpy as np
from pandas.core.groupby.groupby import DataError

import rmm

from cudf.api.types import (
is_categorical_dtype,
is_decimal_dtype,
Expand All @@ -22,16 +17,9 @@ from libcpp.pair cimport pair
from libcpp.utility cimport move
from libcpp.vector cimport vector

import cudf

from cudf._lib.column cimport Column
from cudf._lib.scalar cimport DeviceScalar
from cudf._lib.utils cimport (
columns_from_unique_ptr,
data_from_unique_ptr,
table_view_from_columns,
table_view_from_table,
)
from cudf._lib.utils cimport columns_from_unique_ptr, table_view_from_columns

from cudf._lib.scalar import as_device_scalar

Expand All @@ -44,13 +32,11 @@ from cudf._lib.aggregation cimport (
make_groupby_scan_aggregation,
)
from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.libcpp.functional cimport reference_wrapper
from cudf._lib.cpp.replace cimport replace_policy
from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.cpp.table.table cimport table, table_view
from cudf._lib.cpp.types cimport size_type
from cudf._lib.cpp.utilities.host_span cimport host_span

# The sets below define the possible aggregations that can be performed on
# different dtypes. These strings must be elements of the AggregationKind enum.
Expand Down
2 changes: 0 additions & 2 deletions python/cudf/cudf/_lib/hash.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

from libc.stdint cimport uint32_t
from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libcpp.pair cimport pair
from libcpp.utility cimport move
Expand Down
5 changes: 0 additions & 5 deletions python/cudf/cudf/_lib/interop.pyx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

import cudf

from cpython cimport pycapsule
from libcpp cimport bool
from libcpp.memory cimport shared_ptr, unique_ptr
from libcpp.string cimport string
from libcpp.utility cimport move
from libcpp.vector cimport vector
from pyarrow.lib cimport CTable, pyarrow_unwrap_table, pyarrow_wrap_table
Expand All @@ -18,7 +14,6 @@ from cudf._lib.cpp.interop cimport (
to_arrow as cpp_to_arrow,
to_dlpack as cpp_to_dlpack,
)
from cudf._lib.cpp.io.types cimport column_in_metadata
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.utils cimport columns_from_unique_ptr, table_view_from_columns
Expand Down
4 changes: 0 additions & 4 deletions python/cudf/cudf/_lib/io/utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from cpython.buffer cimport PyBUF_READ
from cpython.memoryview cimport PyMemoryView_FromMemory
from libcpp.map cimport map
from libcpp.memory cimport unique_ptr
from libcpp.pair cimport pair
from libcpp.string cimport string
from libcpp.utility cimport move
from libcpp.vector cimport vector
Expand All @@ -15,7 +13,6 @@ from cudf._lib.cpp.io.types cimport (
data_sink,
datasource,
host_buffer,
io_type,
sink_info,
source_info,
)
Expand All @@ -26,7 +23,6 @@ import errno
import io
import os

import cudf
from cudf.api.types import is_struct_dtype


Expand Down
7 changes: 0 additions & 7 deletions python/cudf/cudf/_lib/join.pyx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

from itertools import chain

import cudf

from libcpp cimport bool
from libcpp.memory cimport make_unique, unique_ptr
from libcpp.pair cimport pair
from libcpp.utility cimport move
from libcpp.vector cimport vector

cimport cudf._lib.cpp.join as cpp_join
from cudf._lib.column cimport Column
from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.cpp.types cimport data_type, size_type, type_id
from cudf._lib.utils cimport table_view_from_columns
Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/_lib/json.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# cython: boundscheck = False


import io
import os
from collections import abc
Expand All @@ -16,13 +15,12 @@ from libcpp.utility cimport move
from libcpp.vector cimport vector

cimport cudf._lib.cpp.io.types as cudf_io_types
cimport cudf._lib.cpp.types as libcudf_types
from cudf._lib.cpp.io.json cimport (
json_reader_options,
read_json as libcudf_read_json,
schema_element,
)
from cudf._lib.cpp.types cimport data_type, size_type, type_id
from cudf._lib.cpp.types cimport data_type, size_type
from cudf._lib.io.utils cimport make_source_info, update_struct_field_names
from cudf._lib.types cimport dtype_to_data_type
from cudf._lib.utils cimport data_from_unique_ptr
Expand Down
10 changes: 1 addition & 9 deletions python/cudf/cudf/_lib/labeling.pyx
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2022, NVIDIA CORPORATION.

from enum import IntEnum

import numpy as np

from libc.stdint cimport uint32_t
from libcpp cimport bool as cbool
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

from cudf._lib.column cimport Column

from cudf._lib.replace import replace_nulls

from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.labeling cimport inclusive, label_bins as cpp_label_bins
Expand Down
12 changes: 2 additions & 10 deletions python/cudf/cudf/_lib/lists.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ from cudf._lib.cpp.lists.combine cimport (
concatenate_null_policy,
concatenate_rows as cpp_concatenate_rows,
)
from cudf._lib.cpp.lists.contains cimport contains, index_of as cpp_index_of
from cudf._lib.cpp.lists.count_elements cimport (
count_elements as cpp_count_elements,
)
from cudf._lib.cpp.lists.explode cimport explode_outer as cpp_explode_outer
from cudf._lib.cpp.lists.extract cimport extract_list_element
from cudf._lib.cpp.lists.lists_column_view cimport lists_column_view
from cudf._lib.cpp.lists.sorting cimport sort_lists as cpp_sort_lists
from cudf._lib.cpp.lists.stream_compaction cimport distinct as cpp_distinct
Expand All @@ -26,20 +28,10 @@ from cudf._lib.cpp.types cimport (
nan_equality,
null_equality,
null_order,
null_policy,
order,
size_type,
)
from cudf._lib.scalar cimport DeviceScalar
from cudf._lib.types cimport (
underlying_type_t_null_order,
underlying_type_t_order,
)

from cudf.core.dtypes import ListDtype

from cudf._lib.cpp.lists.contains cimport contains, index_of as cpp_index_of
from cudf._lib.cpp.lists.extract cimport extract_list_element
from cudf._lib.utils cimport columns_from_unique_ptr, table_view_from_columns


Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/merge.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from libcpp.utility cimport move
from libcpp.vector cimport vector

cimport cudf._lib.cpp.types as libcudf_types
from cudf._lib.column cimport Column
from cudf._lib.cpp.merge cimport merge as cpp_merge
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.table.table_view cimport table_view
Expand Down
Loading

0 comments on commit 0603167

Please sign in to comment.