Skip to content

Commit

Permalink
Fix style issues in 2.0 feature branch (rapidsai#14918)
Browse files Browse the repository at this point in the history
This PR fixes all style issues in pandas-2.0 feature branch
  • Loading branch information
galipremsagar authored Jan 29, 2024
1 parent eae873e commit dbf08cb
Show file tree
Hide file tree
Showing 31 changed files with 43 additions and 79 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,3 @@ jobs:
# repo: context.repo.repo,
# body: `${summary_comment}\n\nHere is [a link to the full test summary](${summary_url}).\n`
# })

1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import rmm
import cudf
import cudf._lib as libcudf
from cudf._lib import pylibcudf
from cudf.api.types import _is_categorical_dtype, _is_datetime64tz_dtype
from cudf.core.buffer import (
Buffer,
ExposureTrackedBuffer,
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

import cupy as cp
import numpy as np
import pandas as pd
from pandas.api import types as pd_types

import cudf
import pandas as pd
from cudf.core._compat import PANDAS_GE_150
from cudf.core.dtypes import ( # noqa: F401
_BaseDtype,
Expand All @@ -30,7 +31,6 @@
is_list_dtype,
is_struct_dtype,
)
from pandas.api import types as pd_types


def is_numeric_dtype(obj):
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
is_scalar,
is_timedelta64_dtype,
)

from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_220
from cudf.core.buffer import Buffer, cuda_array_interface_wrapper
from cudf.core.column import ColumnBase, as_column, column, string
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/core/column/interval.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Copyright (c) 2018-2024, NVIDIA CORPORATION.
from typing import Optional

import pyarrow as pa
import pandas as pd
import pyarrow as pa

import cudf

from cudf.api.types import _is_interval_dtype
from cudf.core.column import StructColumn
from cudf.core.dtypes import CategoricalDtype, IntervalDtype
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/core/column/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
from cudf import _lib as libcudf
from cudf._typing import ColumnBinaryOperand, DatetimeLikeScalar, Dtype
from cudf.api.types import is_scalar, is_timedelta64_dtype
from cudf.core._compat import PANDAS_GE_200
from cudf.core.buffer import Buffer, acquire_spill_lock
from cudf.core.column import ColumnBase, column, string
from cudf.utils.dtypes import np_to_pa_dtype
from cudf.utils.utils import _all_bools_with_nulls
from cudf.core._compat import PANDAS_GE_200


_dtype_to_format_conversion = {
"timedelta64[ns]": "%D days %H:%M:%S",
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6099,7 +6099,6 @@ def _reduce(
numeric_only=False,
**kwargs,
):

source = self

if axis is None:
Expand Down
14 changes: 7 additions & 7 deletions python/cudf/cudf/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
from typing import Any, Callable, Dict, List, Tuple, Type, Union

import numpy as np
import pandas as pd
import pyarrow as pa
from pandas.api import types as pd_types
from pandas.api.extensions import ExtensionDtype
from pandas.core.dtypes.dtypes import (
CategoricalDtype as pd_CategoricalDtype,
CategoricalDtypeType as pd_CategoricalDtypeType,
)

import cudf
import pandas as pd
from cudf._typing import Dtype
from cudf.core._compat import PANDAS_GE_150
from cudf.core.abc import Serializable
from cudf.core.buffer import Buffer
from cudf.utils.docutils import doc_apply
from pandas.api import types as pd_types
from pandas.api.extensions import ExtensionDtype
from pandas.core.dtypes.dtypes import (
CategoricalDtype as pd_CategoricalDtype,
CategoricalDtypeType as pd_CategoricalDtypeType,
)

if PANDAS_GE_150:
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
Expand Down
8 changes: 6 additions & 2 deletions python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
)
from cudf.core.join._join_helpers import _match_join_keys
from cudf.utils.dtypes import is_column_like
from cudf.utils.utils import NotIterable, _external_only_api, _is_same_name
from cudf.utils.nvtx_annotation import _cudf_nvtx_annotate
from cudf.utils.utils import NotIterable, _external_only_api, _is_same_name


def _maybe_indices_to_slice(indices: cp.ndarray) -> Union[slice, cp.ndarray]:
Expand Down Expand Up @@ -726,7 +726,11 @@ def _compute_validity_mask(self, index, row_tuple, max_length):
[
frame,
cudf.DataFrame(
{"idx": cudf.Series(column.as_column(range(len(frame))))}
{
"idx": cudf.Series(
column.as_column(range(len(frame)))
)
}
),
],
axis=1,
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

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

import cudf
import pandas as pd
from cudf._lib.unary import is_nan
from cudf.api.types import (
_is_categorical_dtype,
Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from pandas.api import types as pd_types

import cudf
from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_210, PANDAS_GE_214
from cudf.api import types

from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_210, PANDAS_GE_214
from cudf.testing._utils import expect_warning_if


Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_applymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from cudf import NA, DataFrame
from cudf.testing import _utils as utils
from cudf.core._compat import PANDAS_GE_210
from cudf.testing import _utils as utils


@pytest.mark.parametrize(
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/tests/test_array_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2018-2023, NVIDIA CORPORATION.
# Copyright (c) 2018-2024, NVIDIA CORPORATION.

import numpy as np
import pandas as pd
import pytest
Expand Down
5 changes: 0 additions & 5 deletions python/cudf/cudf/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ def test_categorical_set_categories_preserves_order():


def test_categorical_as_ordered(pd_str_cat):

pd_sr = pd.Series(pd_str_cat.copy().set_ordered(False))
cd_sr = cudf.Series(pd_str_cat.copy().set_ordered(False))

Expand All @@ -362,7 +361,6 @@ def test_categorical_as_ordered(pd_str_cat):


def test_categorical_as_unordered(pd_str_cat):

pd_sr = pd.Series(pd_str_cat.copy().set_ordered(True))
cd_sr = cudf.Series(pd_str_cat.copy().set_ordered(True))

Expand All @@ -380,7 +378,6 @@ def test_categorical_as_unordered(pd_str_cat):
@pytest.mark.parametrize("from_ordered", [True, False])
@pytest.mark.parametrize("to_ordered", [True, False])
def test_categorical_reorder_categories(pd_str_cat, from_ordered, to_ordered):

pd_sr = pd.Series(pd_str_cat.copy().set_ordered(from_ordered))
cd_sr = cudf.Series(pd_str_cat.copy().set_ordered(from_ordered))

Expand All @@ -401,7 +398,6 @@ def test_categorical_reorder_categories(pd_str_cat, from_ordered, to_ordered):


def test_categorical_add_categories(pd_str_cat):

pd_sr = pd.Series(pd_str_cat.copy())
cd_sr = cudf.Series(pd_str_cat.copy())

Expand All @@ -419,7 +415,6 @@ def test_categorical_add_categories(pd_str_cat):


def test_categorical_remove_categories(pd_str_cat):

pd_sr = pd.Series(pd_str_cat.copy())
cd_sr = cudf.Series(pd_str_cat.copy())

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_column_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import pytest

import cudf
from cudf.core._compat import PANDAS_GE_200
from cudf.core.column_accessor import ColumnAccessor
from cudf.testing._utils import assert_eq
from cudf.core._compat import PANDAS_GE_200

simple_test_data = [
{},
Expand Down
7 changes: 3 additions & 4 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright (c) 2018-2024, NVIDIA CORPORATION.

import warnings
from contextlib import contextmanager
from decimal import Decimal

import warnings
import numpy as np
import pandas as pd
import pytest

from contextlib import contextmanager

import cudf as gd
from cudf.api.types import _is_categorical_dtype
from cudf.core._compat import PANDAS_GE_150, PANDAS_LT_140, PANDAS_GE_200
from cudf.core._compat import PANDAS_GE_150, PANDAS_GE_200, PANDAS_LT_140
from cudf.core.dtypes import Decimal32Dtype, Decimal64Dtype, Decimal128Dtype
from cudf.testing._utils import (
assert_eq,
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import cudf
from cudf import read_csv
from cudf.core._compat import PANDAS_LT_140, PANDAS_GE_200
from cudf.core._compat import PANDAS_GE_200, PANDAS_LT_140
from cudf.testing._utils import assert_eq, assert_exceptions_equal


Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2022, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.

import numpy as np

Expand Down
24 changes: 7 additions & 17 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datetime
import operator
import warnings

import cupy as cp
import numpy as np
Expand All @@ -10,15 +11,14 @@
import pytest

import cudf
import warnings
import cudf.testing.dataset_generator as dataset_generator
from cudf import DataFrame, Series
from cudf.core._compat import (
PANDAS_GE_150,
PANDAS_LT_140,
PANDAS_EQ_200,
PANDAS_GE_150,
PANDAS_GE_200,
PANDAS_GE_210,
PANDAS_LT_140,
)
from cudf.core.index import DatetimeIndex
from cudf.testing._utils import (
Expand Down Expand Up @@ -623,22 +623,13 @@ def test_datetime_dataframe():
@pytest.mark.parametrize("dayfirst", [True, False])
def test_cudf_to_datetime(data, dayfirst):
pd_data = data
is_string_data = False
if isinstance(pd_data, (pd.Series, pd.DataFrame, pd.Index)):
gd_data = cudf.from_pandas(pd_data)
is_string_data = (
gd_data.ndim == 1
and not gd_data.empty
and gd_data.dtype.kind == "O"
)
else:
if type(pd_data).__module__ == np.__name__:
gd_data = cp.array(pd_data)
else:
gd_data = pd_data
is_string_data = isinstance(gd_data, list) and isinstance(
next(iter(gd_data), None), str
)

expected = pd.to_datetime(pd_data, dayfirst=dayfirst)
actual = cudf.to_datetime(gd_data, dayfirst=dayfirst)
Expand Down Expand Up @@ -696,7 +687,6 @@ def test_to_datetime_errors(data):


def test_to_datetime_not_implemented():

with pytest.raises(NotImplementedError):
cudf.to_datetime([], exact=False)

Expand Down Expand Up @@ -817,7 +807,6 @@ def test_to_datetime_different_formats_notimplemented():


def test_datetime_can_cast_safely():

sr = cudf.Series(
["1679-01-01", "2000-01-31", "2261-01-01"], dtype="datetime64[ms]"
)
Expand Down Expand Up @@ -938,7 +927,6 @@ def test_str_to_datetime_error():
@pytest.mark.parametrize("data_dtype", DATETIME_TYPES)
@pytest.mark.parametrize("other_dtype", DATETIME_TYPES)
def test_datetime_subtract(data, other, data_dtype, other_dtype):

gsr = cudf.Series(data, dtype=data_dtype)
psr = gsr.to_pandas()

Expand Down Expand Up @@ -1580,7 +1568,8 @@ def test_date_range_start_end_freq(request, start, end, freq):
request.applymarker(
pytest.mark.xfail(
condition=(
not PANDAS_GE_200 and isinstance(freq, dict)
not PANDAS_GE_200
and isinstance(freq, dict)
and freq.get("hours", None) == 10
and freq.get("days", None) == 57
and freq.get("nanoseconds", None) == 3
Expand Down Expand Up @@ -1634,7 +1623,8 @@ def test_date_range_start_freq_periods(request, start, freq, periods):
request.applymarker(
pytest.mark.xfail(
condition=(
not PANDAS_GE_200 and isinstance(freq, dict)
not PANDAS_GE_200
and isinstance(freq, dict)
and freq.get("hours", None) == 10
and freq.get("days", None) == 57
and freq.get("nanoseconds", None) == 3
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/tests/test_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@pytest.mark.parametrize("nulls", ["one", "some", "all", "none"])
@pytest.mark.parametrize("inplace", [True, False])
def test_dropna_series(data, nulls, inplace):

psr = pd.Series(data)

if len(data) > 0:
Expand Down
5 changes: 1 addition & 4 deletions python/cudf/cudf/tests/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

import cudf
from cudf import concat
from cudf.testing._utils import (
assert_eq,
assert_exceptions_equal,
)
from cudf.testing._utils import assert_eq, assert_exceptions_equal

# TODO: PANDAS 1.0 support
# Revisit drop_duplicates() tests to update parameters like ignore_index.
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from cudf.api.extensions import no_default
from cudf.core._compat import (
PANDAS_GE_150,
PANDAS_LT_140,
PANDAS_GE_200,
PANDAS_GE_210,
PANDAS_LT_140,
)
from cudf.core.udf._ops import arith_ops, comparison_ops, unary_ops
from cudf.core.udf.groupby_typing import SUPPORTED_GROUPBY_NUMPY_TYPES
Expand Down
7 changes: 1 addition & 6 deletions python/cudf/cudf/tests/test_monotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

import cudf
from cudf import Index, MultiIndex, Series
from cudf.core.index import (
CategoricalIndex,
DatetimeIndex,
RangeIndex,
)
from cudf.core.index import CategoricalIndex, DatetimeIndex, RangeIndex
from cudf.testing._utils import assert_eq


Expand Down Expand Up @@ -46,7 +42,6 @@ def test_range_index(testrange):
],
)
def test_generic_index(testlist):

index = Index(testlist)
index_pd = pd.Index(testlist)

Expand Down
Loading

0 comments on commit dbf08cb

Please sign in to comment.