diff --git a/python/cudf/cudf/__init__.py b/python/cudf/cudf/__init__.py index 049cec77d9c..273ab147241 100644 --- a/python/cudf/cudf/__init__.py +++ b/python/cudf/cudf/__init__.py @@ -58,26 +58,6 @@ StructDtype, ) from cudf.core.groupby import Grouper -from cudf.core.ops import ( - add, - arccos, - arcsin, - arctan, - cos, - exp, - floor_divide, - log, - logical_and, - logical_not, - logical_or, - multiply, - remainder, - sin, - sqrt, - subtract, - tan, - true_divide, -) from cudf.core.reshape import ( concat, get_dummies, diff --git a/python/cudf/cudf/core/_base_index.py b/python/cudf/cudf/core/_base_index.py index 4e09d3868f5..e05c55bd78f 100644 --- a/python/cudf/cudf/core/_base_index.py +++ b/python/cudf/cudf/core/_base_index.py @@ -3,7 +3,6 @@ from __future__ import annotations import pickle -import warnings from functools import cached_property from typing import Any, Set @@ -1556,27 +1555,6 @@ def _split_columns_by_levels(self, levels): def _split(self, splits): raise NotImplementedError - def sample( - self, - n=None, - frac=None, - replace=False, - weights=None, - random_state=None, - axis=None, - ignore_index=False, - ): - warnings.warn( - "Index.sample is deprecated and will be removed.", FutureWarning, - ) - return cudf.core.index._index_from_data( - self.to_frame() - .sample( - n, frac, replace, weights, random_state, axis, ignore_index - ) - ._data - ) - def _get_result_name(left_name, right_name): if left_name == right_name: diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 4982b75f753..233a0b0beda 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -2023,16 +2023,6 @@ def update( def __iter__(self): return iter(self._column_names) - @_cudf_nvtx_annotate - def iteritems(self): - """Iterate over column names and series pairs""" - warnings.warn( - "iteritems is deprecated and will be removed in a future version. " - "Use .items instead.", - FutureWarning, - ) - return self.items() - @_cudf_nvtx_annotate def items(self): """Iterate over column names and series pairs""" @@ -3361,22 +3351,6 @@ def merge( - For outer joins, the result will be the union of categories from both sides. """ - if indicator: - raise NotImplementedError( - "Only indicator=False is currently supported" - ) - - if lsuffix or rsuffix: - raise ValueError( - "The lsuffix and rsuffix keywords have been replaced with the " - "``suffixes=`` keyword. " - "Please provide the following instead: \n\n" - " suffixes=('%s', '%s')" - % (lsuffix or "_x", rsuffix or "_y") - ) - else: - lsuffix, rsuffix = suffixes - # Compute merge gdf_result = super()._merge( right, @@ -3389,6 +3363,8 @@ def merge( sort=sort, indicator=indicator, suffixes=suffixes, + lsuffix=lsuffix, + rsuffix=rsuffix, ) return gdf_result @@ -6341,7 +6317,7 @@ def from_pandas(obj, nan_as_null=None): @_cudf_nvtx_annotate def merge(left, right, *args, **kwargs): - return left.merge(right, *args, **kwargs) + return super(type(left), left)._merge(right, *args, **kwargs) # a bit of fanciness to inject docstring with left parameter diff --git a/python/cudf/cudf/core/frame.py b/python/cudf/cudf/core/frame.py index b0a0436655c..a9d7fce9d9b 100644 --- a/python/cudf/cudf/core/frame.py +++ b/python/cudf/cudf/core/frame.py @@ -2298,589 +2298,6 @@ def _get_sorted_inds(self, by=None, ascending=True, na_position="last"): return libcudf.sort.order_by(to_sort, ascending, na_position) - @_cudf_nvtx_annotate - def sin(self): - """ - Get Trigonometric sine, element-wise. - - Returns - ------- - DataFrame/Series/Index - Result of the trigonometric operation. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([0.0, 0.32434, 0.5, 45, 90, 180, 360]) - >>> ser - 0 0.00000 - 1 0.32434 - 2 0.50000 - 3 45.00000 - 4 90.00000 - 5 180.00000 - 6 360.00000 - dtype: float64 - >>> ser.sin() - 0 0.000000 - 1 0.318683 - 2 0.479426 - 3 0.850904 - 4 0.893997 - 5 -0.801153 - 6 0.958916 - dtype: float64 - - `sin` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [0.0, 5, 10, 15], - ... 'second': [100.0, 360, 720, 300]}) - >>> df - first second - 0 0.0 100.0 - 1 5.0 360.0 - 2 10.0 720.0 - 3 15.0 300.0 - >>> df.sin() - first second - 0 0.000000 -0.506366 - 1 -0.958924 0.958916 - 2 -0.544021 -0.544072 - 3 0.650288 -0.999756 - - `sin` operation on Index: - - >>> index = cudf.Index([-0.4, 100, -180, 90]) - >>> index - Float64Index([-0.4, 100.0, -180.0, 90.0], dtype='float64') - >>> index.sin() - Float64Index([-0.3894183423086505, -0.5063656411097588, - 0.8011526357338306, 0.8939966636005579], - dtype='float64') - """ - warnings.warn( - "sin is deprecated and will be removed. Use numpy.sin instead", - FutureWarning, - ) - - return self._unaryop("sin") - - @_cudf_nvtx_annotate - def cos(self): - """ - Get Trigonometric cosine, element-wise. - - Returns - ------- - DataFrame/Series/Index - Result of the trigonometric operation. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([0.0, 0.32434, 0.5, 45, 90, 180, 360]) - >>> ser - 0 0.00000 - 1 0.32434 - 2 0.50000 - 3 45.00000 - 4 90.00000 - 5 180.00000 - 6 360.00000 - dtype: float64 - >>> ser.cos() - 0 1.000000 - 1 0.947861 - 2 0.877583 - 3 0.525322 - 4 -0.448074 - 5 -0.598460 - 6 -0.283691 - dtype: float64 - - `cos` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [0.0, 5, 10, 15], - ... 'second': [100.0, 360, 720, 300]}) - >>> df - first second - 0 0.0 100.0 - 1 5.0 360.0 - 2 10.0 720.0 - 3 15.0 300.0 - >>> df.cos() - first second - 0 1.000000 0.862319 - 1 0.283662 -0.283691 - 2 -0.839072 -0.839039 - 3 -0.759688 -0.022097 - - `cos` operation on Index: - - >>> index = cudf.Index([-0.4, 100, -180, 90]) - >>> index - Float64Index([-0.4, 100.0, -180.0, 90.0], dtype='float64') - >>> index.cos() - Float64Index([ 0.9210609940028851, 0.8623188722876839, - -0.5984600690578581, -0.4480736161291701], - dtype='float64') - """ - warnings.warn( - "cos is deprecated and will be removed. Use numpy.cos instead", - FutureWarning, - ) - - return self._unaryop("cos") - - @_cudf_nvtx_annotate - def tan(self): - """ - Get Trigonometric tangent, element-wise. - - Returns - ------- - DataFrame/Series/Index - Result of the trigonometric operation. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([0.0, 0.32434, 0.5, 45, 90, 180, 360]) - >>> ser - 0 0.00000 - 1 0.32434 - 2 0.50000 - 3 45.00000 - 4 90.00000 - 5 180.00000 - 6 360.00000 - dtype: float64 - >>> ser.tan() - 0 0.000000 - 1 0.336213 - 2 0.546302 - 3 1.619775 - 4 -1.995200 - 5 1.338690 - 6 -3.380140 - dtype: float64 - - `tan` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [0.0, 5, 10, 15], - ... 'second': [100.0, 360, 720, 300]}) - >>> df - first second - 0 0.0 100.0 - 1 5.0 360.0 - 2 10.0 720.0 - 3 15.0 300.0 - >>> df.tan() - first second - 0 0.000000 -0.587214 - 1 -3.380515 -3.380140 - 2 0.648361 0.648446 - 3 -0.855993 45.244742 - - `tan` operation on Index: - - >>> index = cudf.Index([-0.4, 100, -180, 90]) - >>> index - Float64Index([-0.4, 100.0, -180.0, 90.0], dtype='float64') - >>> index.tan() - Float64Index([-0.4227932187381618, -0.587213915156929, - -1.3386902103511544, -1.995200412208242], - dtype='float64') - """ - warnings.warn( - "tan is deprecated and will be removed. Use numpy.tan instead", - FutureWarning, - ) - - return self._unaryop("tan") - - @_cudf_nvtx_annotate - def asin(self): - """ - Get Trigonometric inverse sine, element-wise. - - The inverse of sine so that, if y = x.sin(), then x = y.asin() - - Returns - ------- - DataFrame/Series/Index - Result of the trigonometric operation. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([-1, 0, 1, 0.32434, 0.5]) - >>> ser.asin() - 0 -1.570796 - 1 0.000000 - 2 1.570796 - 3 0.330314 - 4 0.523599 - dtype: float64 - - `asin` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [-1, 0, 0.5], - ... 'second': [0.234, 0.3, 0.1]}) - >>> df - first second - 0 -1.0 0.234 - 1 0.0 0.300 - 2 0.5 0.100 - >>> df.asin() - first second - 0 -1.570796 0.236190 - 1 0.000000 0.304693 - 2 0.523599 0.100167 - - `asin` operation on Index: - - >>> index = cudf.Index([-1, 0.4, 1, 0.3]) - >>> index - Float64Index([-1.0, 0.4, 1.0, 0.3], dtype='float64') - >>> index.asin() - Float64Index([-1.5707963267948966, 0.41151684606748806, - 1.5707963267948966, 0.3046926540153975], - dtype='float64') - """ - warnings.warn( - "asin is deprecated and will be removed in the future", - FutureWarning, - ) - - return self._unaryop("asin") - - @_cudf_nvtx_annotate - def acos(self): - """ - Get Trigonometric inverse cosine, element-wise. - - The inverse of cos so that, if y = x.cos(), then x = y.acos() - - Returns - ------- - DataFrame/Series/Index - Result of the trigonometric operation. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([-1, 0, 1, 0.32434, 0.5]) - >>> ser.acos() - 0 3.141593 - 1 1.570796 - 2 0.000000 - 3 1.240482 - 4 1.047198 - dtype: float64 - - `acos` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [-1, 0, 0.5], - ... 'second': [0.234, 0.3, 0.1]}) - >>> df - first second - 0 -1.0 0.234 - 1 0.0 0.300 - 2 0.5 0.100 - >>> df.acos() - first second - 0 3.141593 1.334606 - 1 1.570796 1.266104 - 2 1.047198 1.470629 - - `acos` operation on Index: - - >>> index = cudf.Index([-1, 0.4, 1, 0, 0.3]) - >>> index - Float64Index([-1.0, 0.4, 1.0, 0.0, 0.3], dtype='float64') - >>> index.acos() - Float64Index([ 3.141592653589793, 1.1592794807274085, 0.0, - 1.5707963267948966, 1.266103672779499], - dtype='float64') - """ - warnings.warn( - "acos is deprecated and will be removed. Use numpy.acos instead", - FutureWarning, - ) - - result = self.copy(deep=False) - for col in result._data: - min_float_dtype = cudf.utils.dtypes.get_min_float_dtype( - result._data[col] - ) - result._data[col] = result._data[col].astype(min_float_dtype) - result = result._unaryop("acos") - result = result.mask((result < 0) | (result > np.pi + 1)) - return result - - @_cudf_nvtx_annotate - def atan(self): - """ - Get Trigonometric inverse tangent, element-wise. - - The inverse of tan so that, if y = x.tan(), then x = y.atan() - - Returns - ------- - DataFrame/Series/Index - Result of the trigonometric operation. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([-1, 0, 1, 0.32434, 0.5, -10]) - >>> ser - 0 -1.00000 - 1 0.00000 - 2 1.00000 - 3 0.32434 - 4 0.50000 - 5 -10.00000 - dtype: float64 - >>> ser.atan() - 0 -0.785398 - 1 0.000000 - 2 0.785398 - 3 0.313635 - 4 0.463648 - 5 -1.471128 - dtype: float64 - - `atan` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [-1, -10, 0.5], - ... 'second': [0.234, 0.3, 10]}) - >>> df - first second - 0 -1.0 0.234 - 1 -10.0 0.300 - 2 0.5 10.000 - >>> df.atan() - first second - 0 -0.785398 0.229864 - 1 -1.471128 0.291457 - 2 0.463648 1.471128 - - `atan` operation on Index: - - >>> index = cudf.Index([-1, 0.4, 1, 0, 0.3]) - >>> index - Float64Index([-1.0, 0.4, 1.0, 0.0, 0.3], dtype='float64') - >>> index.atan() - Float64Index([-0.7853981633974483, 0.3805063771123649, - 0.7853981633974483, 0.0, - 0.2914567944778671], - dtype='float64') - """ - warnings.warn( - "atan is deprecated and will be removed. Use numpy.atan instead", - FutureWarning, - ) - - return self._unaryop("atan") - - @_cudf_nvtx_annotate - def exp(self): - """ - Get the exponential of all elements, element-wise. - - Exponential is the inverse of the log function, - so that x.exp().log() = x - - Returns - ------- - DataFrame/Series/Index - Result of the element-wise exponential. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([-1, 0, 1, 0.32434, 0.5, -10, 100]) - >>> ser - 0 -1.00000 - 1 0.00000 - 2 1.00000 - 3 0.32434 - 4 0.50000 - 5 -10.00000 - 6 100.00000 - dtype: float64 - >>> ser.exp() - 0 3.678794e-01 - 1 1.000000e+00 - 2 2.718282e+00 - 3 1.383117e+00 - 4 1.648721e+00 - 5 4.539993e-05 - 6 2.688117e+43 - dtype: float64 - - `exp` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [-1, -10, 0.5], - ... 'second': [0.234, 0.3, 10]}) - >>> df - first second - 0 -1.0 0.234 - 1 -10.0 0.300 - 2 0.5 10.000 - >>> df.exp() - first second - 0 0.367879 1.263644 - 1 0.000045 1.349859 - 2 1.648721 22026.465795 - - `exp` operation on Index: - - >>> index = cudf.Index([-1, 0.4, 1, 0, 0.3]) - >>> index - Float64Index([-1.0, 0.4, 1.0, 0.0, 0.3], dtype='float64') - >>> index.exp() - Float64Index([0.36787944117144233, 1.4918246976412703, - 2.718281828459045, 1.0, 1.3498588075760032], - dtype='float64') - """ - warnings.warn( - "exp is deprecated and will be removed. Use numpy.exp instead", - FutureWarning, - ) - - return self._unaryop("exp") - - @_cudf_nvtx_annotate - def log(self): - """ - Get the natural logarithm of all elements, element-wise. - - Natural logarithm is the inverse of the exp function, - so that x.log().exp() = x - - Returns - ------- - DataFrame/Series/Index - Result of the element-wise natural logarithm. - - Examples - -------- - >>> import cudf - >>> ser = cudf.Series([-1, 0, 1, 0.32434, 0.5, -10, 100]) - >>> ser - 0 -1.00000 - 1 0.00000 - 2 1.00000 - 3 0.32434 - 4 0.50000 - 5 -10.00000 - 6 100.00000 - dtype: float64 - >>> ser.log() - 0 NaN - 1 -inf - 2 0.000000 - 3 -1.125963 - 4 -0.693147 - 5 NaN - 6 4.605170 - dtype: float64 - - `log` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [-1, -10, 0.5], - ... 'second': [0.234, 0.3, 10]}) - >>> df - first second - 0 -1.0 0.234 - 1 -10.0 0.300 - 2 0.5 10.000 - >>> df.log() - first second - 0 NaN -1.452434 - 1 NaN -1.203973 - 2 -0.693147 2.302585 - - `log` operation on Index: - - >>> index = cudf.Index([10, 11, 500.0]) - >>> index - Float64Index([10.0, 11.0, 500.0], dtype='float64') - >>> index.log() - Float64Index([2.302585092994046, 2.3978952727983707, - 6.214608098422191], dtype='float64') - """ - warnings.warn( - "log is deprecated and will be removed. Use numpy.log instead", - FutureWarning, - ) - - return self._unaryop("log") - - @_cudf_nvtx_annotate - def sqrt(self): - """ - Get the non-negative square-root of all elements, element-wise. - - Returns - ------- - DataFrame/Series/Index - Result of the non-negative - square-root of each element. - - Examples - -------- - >>> import cudf - >>> import cudf - >>> ser = cudf.Series([10, 25, 81, 1.0, 100]) - >>> ser - 0 10.0 - 1 25.0 - 2 81.0 - 3 1.0 - 4 100.0 - dtype: float64 - >>> ser.sqrt() - 0 3.162278 - 1 5.000000 - 2 9.000000 - 3 1.000000 - 4 10.000000 - dtype: float64 - - `sqrt` operation on DataFrame: - - >>> df = cudf.DataFrame({'first': [-10.0, 100, 625], - ... 'second': [1, 2, 0.4]}) - >>> df - first second - 0 -10.0 1.0 - 1 100.0 2.0 - 2 625.0 0.4 - >>> df.sqrt() - first second - 0 NaN 1.000000 - 1 10.0 1.414214 - 2 25.0 0.632456 - - `sqrt` operation on Index: - - >>> index = cudf.Index([-10.0, 100, 625]) - >>> index - Float64Index([-10.0, 100.0, 625.0], dtype='float64') - >>> index.sqrt() - Float64Index([nan, 10.0, 25.0], dtype='float64') - """ - warnings.warn( - "sqrt is deprecated and will be removed. Use numpy.sqrt instead", - FutureWarning, - ) - - return self._unaryop("sqrt") - @_cudf_nvtx_annotate def abs(self): """ @@ -2907,84 +2324,6 @@ def abs(self): """ return self._unaryop("abs") - # Rounding - @_cudf_nvtx_annotate - def ceil(self): - """ - Rounds each value upward to the smallest integral value not less - than the original. - - Returns - ------- - DataFrame or Series - Ceiling value of each element. - - Examples - -------- - >>> import cudf - >>> series = cudf.Series([1.1, 2.8, 3.5, 4.5]) - >>> series - 0 1.1 - 1 2.8 - 2 3.5 - 3 4.5 - dtype: float64 - >>> series.ceil() - 0 2.0 - 1 3.0 - 2 4.0 - 3 5.0 - dtype: float64 - """ - - warnings.warn( - "Series.ceil and DataFrame.ceil are deprecated and will be " - "removed in the future", - FutureWarning, - ) - - return self._unaryop("ceil") - - @_cudf_nvtx_annotate - def floor(self): - """Rounds each value downward to the largest integral value not greater - than the original. - - Returns - ------- - DataFrame or Series - Flooring value of each element. - - Examples - -------- - >>> import cudf - >>> series = cudf.Series([-1.9, 2, 0.2, 1.5, 0.0, 3.0]) - >>> series - 0 -1.9 - 1 2.0 - 2 0.2 - 3 1.5 - 4 0.0 - 5 3.0 - dtype: float64 - >>> series.floor() - 0 -2.0 - 1 2.0 - 2 0.0 - 3 1.0 - 4 0.0 - 5 3.0 - dtype: float64 - """ - - warnings.warn( - "Series.floor and DataFrame.floor are deprecated and will be " - "removed in the future.", - FutureWarning, - ) - - return self._unaryop("floor") - @_cudf_nvtx_annotate def scale(self): """ @@ -3033,7 +2372,25 @@ def _merge( sort=False, indicator=False, suffixes=("_x", "_y"), + lsuffix=None, + rsuffix=None, ): + if indicator: + raise NotImplementedError( + "Only indicator=False is currently supported" + ) + + if lsuffix or rsuffix: + raise ValueError( + "The lsuffix and rsuffix keywords have been replaced with the " + "``suffixes=`` keyword. " + "Please provide the following instead: \n\n" + " suffixes=('%s', '%s')" + % (lsuffix or "_x", rsuffix or "_y") + ) + else: + lsuffix, rsuffix = suffixes + lhs, rhs = self, right merge_cls = Merge if how == "right": diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index 342a4e52101..7e116607017 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -2306,8 +2306,6 @@ def astype(self, dtype, copy=False, errors="raise", **kwargs): - ``raise`` : allow exceptions to be raised - ``ignore`` : suppress exceptions. On error return original object. - - ``warn`` : prints last exceptions as warnings and - return original object. **kwargs : extra arguments to pass on to the constructor Returns @@ -2395,25 +2393,14 @@ def astype(self, dtype, copy=False, errors="raise", **kwargs): 1 2 dtype: int64 """ - if errors not in ("ignore", "warn", "raise"): + if errors not in ("ignore", "raise"): raise ValueError("invalid error value specified") - elif errors == "warn": - warnings.warn( - "Specifying errors='warn' is deprecated and will be removed " - "in a future release.", - FutureWarning, - ) try: data = super().astype(dtype, copy, **kwargs) except Exception as e: if errors == "raise": raise e - elif errors == "warn": - import traceback - - tb = traceback.format_exc() - warnings.warn(tb) return self return self._from_data(data, index=self._index) diff --git a/python/cudf/cudf/core/ops.py b/python/cudf/cudf/core/ops.py deleted file mode 100644 index c2a8c0e72fb..00000000000 --- a/python/cudf/cudf/core/ops.py +++ /dev/null @@ -1,227 +0,0 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. -import warnings -from numbers import Number - -import numpy as np - -from cudf.core.frame import Frame - -""" Global __array_ufunc__ methods -""" - - -def sin(arbitrary): - warnings.warn( - "sin is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.sin(arbitrary) - else: - return getattr(arbitrary, "sin")() - - -def cos(arbitrary): - warnings.warn( - "cos is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.cos(arbitrary) - else: - return getattr(arbitrary, "cos")() - - -def tan(arbitrary): - warnings.warn( - "tan is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.tan(arbitrary) - else: - return getattr(arbitrary, "tan")() - - -def arcsin(arbitrary): - warnings.warn( - "arcsin is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.arcsin(arbitrary) - else: - return getattr(arbitrary, "asin")() - - -def arccos(arbitrary): - warnings.warn( - "arcsin is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.arccos(arbitrary) - else: - return getattr(arbitrary, "acos")() - - -def arctan(arbitrary): - warnings.warn( - "arctan is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.arctan(arbitrary) - else: - return getattr(arbitrary, "atan")() - - -def exp(arbitrary): - warnings.warn( - "exp is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.exp(arbitrary) - else: - return getattr(arbitrary, "exp")() - - -def log(arbitrary): - warnings.warn( - "log is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.log(arbitrary) - else: - return getattr(arbitrary, "log")() - - -def sqrt(arbitrary): - warnings.warn( - "sqrt is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.sqrt(arbitrary) - else: - return getattr(arbitrary, "sqrt")() - - -def logical_not(arbitrary): - warnings.warn( - "logical_not is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(arbitrary, Number): - return np.logical_not(arbitrary) - else: - return getattr(arbitrary, "logical_not")() - - -def logical_and(lhs, rhs): - warnings.warn( - "logical_and is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.logical_and(lhs, rhs) - else: - return getattr(lhs, "logical_and")(rhs) - - -def logical_or(lhs, rhs): - warnings.warn( - "logical_or is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.logical_or(lhs, rhs) - else: - return getattr(lhs, "logical_or")(rhs) - - -def remainder(lhs, rhs): - warnings.warn( - "remainder is deprecated and will be removed in the future", - FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.mod(lhs, rhs) - elif isinstance(lhs, Frame): - return getattr(lhs, "remainder")(rhs) - else: - return getattr(rhs, "__rmod__")(lhs) - - -def floor_divide(lhs, rhs): - warnings.warn( - "sin is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.floor_divide(lhs, rhs) - elif isinstance(lhs, Frame): - return getattr(lhs, "floordiv")(rhs) - else: - return getattr(rhs, "__rfloordiv__")(lhs) - - -def subtract(lhs, rhs): - warnings.warn( - "sin is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.subtract(lhs, rhs) - elif isinstance(lhs, Frame): - return getattr(lhs, "__sub__")(rhs) - else: - return getattr(rhs, "__rsub__")(lhs) - - -def add(lhs, rhs): - warnings.warn( - "sin is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.add(lhs, rhs) - elif isinstance(rhs, Frame): - return getattr(rhs, "__radd__")(lhs) - else: - return getattr(lhs, "__add__")(rhs) - - -def true_divide(lhs, rhs): - warnings.warn( - "sin is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.true_divide(lhs, rhs) - elif isinstance(rhs, Frame): - return getattr(rhs, "__rtruediv__")(lhs) - else: - return getattr(lhs, "__truediv__")(rhs) - - -def multiply(lhs, rhs): - warnings.warn( - "sin is deprecated and will be removed in the future", FutureWarning, - ) - - if isinstance(lhs, Number) and isinstance(rhs, Number): - return np.multiply(lhs, rhs) - elif isinstance(rhs, Frame): - return getattr(rhs, "__rmul__")(lhs) - else: - return getattr(lhs, "__mul__")(rhs) diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index b1ee9e99dfb..40e09bb11b8 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -5,7 +5,6 @@ import functools import inspect import pickle -import warnings from collections import abc as abc from shutil import get_terminal_size from typing import Any, Dict, MutableMapping, Optional, Set, Tuple, Type, Union @@ -1173,38 +1172,6 @@ def _make_operands_and_index_for_binop( operands = lhs._make_operands_for_binop(other, fill_value, reflect) return operands, lhs._index - @_cudf_nvtx_annotate - def logical_and(self, other): - warnings.warn( - "Series.logical_and is deprecated and will be removed.", - FutureWarning, - ) - return self._binaryop(other, "__l_and__").astype(np.bool_) - - @_cudf_nvtx_annotate - def remainder(self, other): - warnings.warn( - "Series.remainder is deprecated and will be removed.", - FutureWarning, - ) - return self._binaryop(other, "__mod__") - - @_cudf_nvtx_annotate - def logical_or(self, other): - warnings.warn( - "Series.logical_or is deprecated and will be removed.", - FutureWarning, - ) - return self._binaryop(other, "__l_or__").astype(np.bool_) - - @_cudf_nvtx_annotate - def logical_not(self): - warnings.warn( - "Series.logical_not is deprecated and will be removed.", - FutureWarning, - ) - return self._unaryop("not") - @copy_docstring(CategoricalAccessor) # type: ignore @property @_cudf_nvtx_annotate @@ -3160,58 +3127,6 @@ def rename(self, index=None, copy=True): out_data = self._data.copy(deep=copy) return Series._from_data(out_data, self.index, name=index) - @_cudf_nvtx_annotate - def merge( - self, - other, - on=None, - left_on=None, - right_on=None, - left_index=False, - right_index=False, - how="inner", - sort=False, - lsuffix=None, - rsuffix=None, - method="hash", - suffixes=("_x", "_y"), - ): - warnings.warn( - "Series.merge is deprecated and will be removed in a future " - "release. Use cudf.merge instead.", - FutureWarning, - ) - if left_on not in (self.name, None): - raise ValueError( - "Series to other merge uses series name as key implicitly" - ) - - if lsuffix or rsuffix: - raise ValueError( - "The lsuffix and rsuffix keywords have been replaced with the " - "``suffixes=`` keyword. " - "Please provide the following instead: \n\n" - " suffixes=('%s', '%s')" - % (lsuffix or "_x", rsuffix or "_y") - ) - else: - lsuffix, rsuffix = suffixes - - result = super()._merge( - other, - on=on, - left_on=left_on, - right_on=right_on, - left_index=left_index, - right_index=right_index, - how=how, - sort=sort, - indicator=False, - suffixes=suffixes, - ) - - return result - @_cudf_nvtx_annotate def add_prefix(self, prefix): return Series._from_data( diff --git a/python/cudf/cudf/tests/test_binops.py b/python/cudf/cudf/tests/test_binops.py index db12743ac17..aa4075eb887 100644 --- a/python/cudf/cudf/tests/test_binops.py +++ b/python/cudf/cudf/tests/test_binops.py @@ -4,7 +4,6 @@ import decimal import operator import random -from contextlib import contextmanager from itertools import combinations_with_replacement, product import cupy as cp @@ -28,23 +27,6 @@ STRING_TYPES = {"str"} -@contextmanager -def _hide_deprecated_ops_warnings(func, lhs, rhs): - if func in { - cudf.logical_and, - cudf.logical_or, - cudf.remainder, - } and isinstance(lhs, cudf.Series): - name = func.__name__ - with pytest.warns( - FutureWarning, - match=f"Series.{name} is deprecated and will be removed.", - ): - yield - else: - yield - - _binops = [ operator.add, operator.sub, @@ -167,35 +149,6 @@ def test_series_bitwise_binop(binop, obj_class, lhs_dtype, rhs_dtype): np.testing.assert_almost_equal(result.to_numpy(), binop(arr1, arr2)) -_logical_binops = [ - (operator.and_, operator.and_), - (operator.or_, operator.or_), - (np.logical_and, cudf.logical_and), - (np.logical_or, cudf.logical_or), -] - - -@pytest.mark.parametrize("lhstype", _int_types + [np.bool_]) -@pytest.mark.parametrize("rhstype", _int_types + [np.bool_]) -@pytest.mark.parametrize("binop,cubinop", _logical_binops) -def test_series_logical_binop(lhstype, rhstype, binop, cubinop): - arr1 = pd.Series(np.random.choice([True, False], 10)) - if lhstype is not np.bool_: - arr1 = arr1 * (np.random.random(10) * 100).astype(lhstype) - sr1 = Series(arr1) - - arr2 = pd.Series(np.random.choice([True, False], 10)) - if rhstype is not np.bool_: - arr2 = arr2 * (np.random.random(10) * 100).astype(rhstype) - sr2 = Series(arr2) - - with _hide_deprecated_ops_warnings(cubinop, sr1, sr2): - result = cubinop(sr1, sr2) - expect = binop(arr1, arr2) - - utils.assert_eq(result, expect) - - _cmpops = [ operator.lt, operator.gt, @@ -938,54 +891,6 @@ def test_vector_to_none_binops(dtype): utils.assert_eq(expect, got) -@pytest.mark.parametrize( - "lhs", - [ - 1, - 3, - 4, - pd.Series([5, 6, 2]), - pd.Series([0, 10, 20, 30, 3, 4, 5, 6, 2]), - 6, - ], -) -@pytest.mark.parametrize("rhs", [1, 3, 4, pd.Series([5, 6, 2])]) -@pytest.mark.parametrize( - "ops", - [ - (np.remainder, cudf.remainder), - (np.floor_divide, cudf.floor_divide), - (np.subtract, cudf.subtract), - (np.add, cudf.add), - (np.true_divide, cudf.true_divide), - (np.multiply, cudf.multiply), - ], -) -def test_ufunc_ops(lhs, rhs, ops): - np_op, cu_op = ops - - if isinstance(lhs, pd.Series): - culhs = cudf.from_pandas(lhs) - else: - culhs = lhs - - if isinstance(rhs, pd.Series): - curhs = cudf.from_pandas(rhs) - else: - curhs = rhs - - expect = np_op(lhs, rhs) - with _hide_deprecated_ops_warnings(cu_op, culhs, curhs): - got = cu_op(culhs, curhs) - - if np.isscalar(expect): - assert got == expect - else: - utils.assert_eq( - expect, got, - ) - - def dtype_scalar(val, dtype): if dtype == "str": return str(val) diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index 136deb59334..08c8e3485a3 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -2079,13 +2079,12 @@ def test_unaryops_df(pdf, gdf, unaryop): assert_eq(d, g) -@pytest.mark.parametrize("unary_func", ["abs", "floor", "ceil"]) -def test_unary_func_df(pdf, unary_func): +def test_df_abs(pdf): np.random.seed(0) disturbance = pd.Series(np.random.rand(10)) pdf = pdf - 5 + disturbance - d = pdf.apply(getattr(np, unary_func)) - g = getattr(cudf.from_pandas(pdf), unary_func)() + d = pdf.apply(np.abs) + g = cudf.from_pandas(pdf).abs() assert_eq(d, g) @@ -4532,9 +4531,6 @@ def test_empty_df_astype(dtype, args): ), pytest.param("other", marks=pytest.mark.xfail(raises=ValueError)), "ignore", - pytest.param( - "warn", marks=pytest.mark.filterwarnings("ignore:Traceback") - ), ], ) def test_series_astype_error_handling(errors): diff --git a/python/cudf/cudf/tests/test_index.py b/python/cudf/cudf/tests/test_index.py index 80270e62da7..b96b8386b10 100644 --- a/python/cudf/cudf/tests/test_index.py +++ b/python/cudf/cudf/tests/test_index.py @@ -1566,114 +1566,6 @@ def test_interval_index_from_breaks(closed): assert_eq(pindex, gindex) -@pytest.mark.parametrize("n", [0, 2, 5, 10, None]) -@pytest.mark.parametrize("frac", [0.1, 0.5, 1, 2, None]) -@pytest.mark.parametrize("replace", [True, False]) -def test_index_sample_basic(n, frac, replace): - psr = pd.Series([1, 2, 3, 4, 5]) - gindex = cudf.Index(psr) - random_state = 0 - - try: - pout = psr.sample( - n=n, frac=frac, replace=replace, random_state=random_state - ) - except BaseException: - assert_exceptions_equal( - lfunc=psr.sample, - rfunc=gindex.sample, - lfunc_args_and_kwargs=( - [], - { - "n": n, - "frac": frac, - "replace": replace, - "random_state": random_state, - }, - ), - rfunc_args_and_kwargs=( - [], - { - "n": n, - "frac": frac, - "replace": replace, - "random_state": random_state, - }, - ), - compare_error_message=False, - ) - else: - gout = gindex.sample( - n=n, frac=frac, replace=replace, random_state=random_state - ) - - assert pout.shape == gout.shape - - -@pytest.mark.parametrize("n", [2, 5, 10, None]) -@pytest.mark.parametrize("frac", [0.5, 1, 2, None]) -@pytest.mark.parametrize("replace", [True, False]) -@pytest.mark.parametrize("axis", [0, 1]) -def test_multiindex_sample_basic(n, frac, replace, axis): - # as we currently don't support column with same name - if axis == 1 and replace: - return - pdf = pd.DataFrame( - { - "a": [1, 2, 3, 4, 5], - "float": [0.05, 0.2, 0.3, 0.2, 0.25], - "int": [1, 3, 5, 4, 2], - }, - ) - mul_index = cudf.Index(cudf.from_pandas(pdf)) - random_state = 0 - - try: - pout = pdf.sample( - n=n, - frac=frac, - replace=replace, - random_state=random_state, - axis=axis, - ) - except BaseException: - assert_exceptions_equal( - lfunc=pdf.sample, - rfunc=mul_index.sample, - lfunc_args_and_kwargs=( - [], - { - "n": n, - "frac": frac, - "replace": replace, - "random_state": random_state, - "axis": axis, - }, - ), - rfunc_args_and_kwargs=( - [], - { - "n": n, - "frac": frac, - "replace": replace, - "random_state": random_state, - "axis": axis, - }, - ), - ) - else: - gout = mul_index.sample( - n=n, - frac=frac, - replace=replace, - random_state=random_state, - axis=axis, - ) - if axis == 1 and n is None and frac is None: - pout = pout.iloc[:, 0] - assert pout.shape == gout.shape - - @pytest.mark.parametrize( "data", [ diff --git a/python/cudf/cudf/tests/test_joining.py b/python/cudf/cudf/tests/test_joining.py index 69793dc1828..f478216cdcf 100644 --- a/python/cudf/cudf/tests/test_joining.py +++ b/python/cudf/cudf/tests/test_joining.py @@ -1813,8 +1813,8 @@ def test_series_dataframe_mixed_merging(lhs, rhs, how, kwargs): if isinstance(rhs, cudf.Series): check_rhs = rhs.to_frame() - expect = check_lhs.merge(check_rhs, how=how, **kwargs) - got = lhs.merge(rhs, how=how, **kwargs) + expect = cudf.merge(check_lhs, check_rhs, how=how, **kwargs) + got = cudf.merge(lhs, rhs, how=how, **kwargs) assert_join_results_equal(expect, got, how=how) diff --git a/python/cudf/cudf/tests/test_ops.py b/python/cudf/cudf/tests/test_ops.py deleted file mode 100644 index ac3f784ecd4..00000000000 --- a/python/cudf/cudf/tests/test_ops.py +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. - -import numpy as np -import pandas as pd -import pytest - -import cudf -from cudf.testing._utils import assert_eq, gen_rand - - -def test_sqrt_float(): - assert cudf.sqrt(16.0) == 4.0 - assert_eq(cudf.sqrt(cudf.Series([4.0, 9, 16])), cudf.Series([2.0, 3, 4])) - assert_eq( - cudf.sqrt(cudf.DataFrame({"x": [4.0, 9, 16]})), - cudf.DataFrame({"x": [2.0, 3, 4]}), - ) - - -def test_sqrt_integer(): - assert cudf.sqrt(16) == 4 - assert_eq(cudf.sqrt(cudf.Series([4, 9, 16])), cudf.Series([2, 3, 4])) - assert_eq( - cudf.sqrt(cudf.DataFrame({"x": [4, 9, 16]})), - cudf.DataFrame({"x": [2, 3, 4]}), - ) - - -def math_op_test( - dtype, fn, nelem=128, test_df=False, positive_only=False, check_dtype=True -): - np.random.seed(0) - randvals = gen_rand(dtype, nelem, positive_only=positive_only) - h_series = pd.Series(randvals.astype(dtype)) - d_series = cudf.Series(h_series) - - if test_df: - d_in = cudf.DataFrame() - d_in[0] = d_series - h_in = pd.DataFrame() - h_in[0] = h_series - else: - d_in = d_series - h_in = h_series - - expect = fn(h_in) - got = fn(d_in) - - assert_eq(expect, got, check_dtype=check_dtype) - - -params_real_types = [np.float64, np.float32] -int_type = [np.int64, np.int32] - - -# trig - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_sin(dtype, test_df): - math_op_test(dtype, np.sin, test_df=test_df) - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_cos(dtype, test_df): - math_op_test(dtype, np.cos, test_df=test_df) - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_tan(dtype, test_df): - math_op_test(dtype, np.tan, test_df=test_df) - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_asin(dtype, test_df): - math_op_test(dtype, np.arcsin, test_df=test_df) - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_acos(dtype, test_df): - math_op_test(dtype, np.arccos, test_df=test_df, check_dtype=False) - - -@pytest.mark.parametrize("dtype", int_type) -@pytest.mark.parametrize("test_df", [False, True]) -def test_acos_integer(dtype, test_df): - math_op_test(dtype, np.arccos, test_df=test_df, check_dtype=False) - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_atan(dtype, test_df): - math_op_test(dtype, np.arctan, test_df=test_df) - - -# exponential - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_exp(dtype, test_df): - math_op_test(dtype, np.exp, test_df=test_df) - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_log(dtype, test_df): - math_op_test(dtype, np.log, test_df=test_df, positive_only=True) - - -# power - - -@pytest.mark.parametrize("dtype", params_real_types) -@pytest.mark.parametrize("test_df", [False, True]) -def test_sqrt(dtype, test_df): - math_op_test(dtype, np.sqrt, test_df=test_df, positive_only=True) diff --git a/python/cudf/cudf/tests/test_unaops.py b/python/cudf/cudf/tests/test_unaops.py index bc9edacb68a..3f2f2072758 100644 --- a/python/cudf/cudf/tests/test_unaops.py +++ b/python/cudf/cudf/tests/test_unaops.py @@ -31,79 +31,12 @@ def test_series_invert(dtype): np.testing.assert_equal((~sr).to_numpy(), ~arr) -@pytest.mark.parametrize("dtype", utils.INTEGER_TYPES + ["bool"]) -def test_series_not(dtype): - import pandas as pd - - dtype = cudf.dtype(dtype).type - arr = pd.Series(np.random.choice([True, False], 1000)).astype(dtype) - if dtype is not np.bool_: - arr = arr * (np.random.random(1000) * 100).astype(dtype) - sr = Series(arr) - - with pytest.warns(FutureWarning, match="logical_not is deprecated"): - result = cudf.logical_not(sr).to_numpy() - expect = np.logical_not(arr) - np.testing.assert_equal(result, expect) - np.testing.assert_equal((~sr).to_numpy(), ~arr) - - def test_series_neg(): arr = np.random.random(100) * 100 sr = Series(arr) np.testing.assert_equal((-sr).to_numpy(), -arr) -def test_series_ceil(): - arr = np.random.random(100) * 100 - sr = Series(arr) - with pytest.warns( - FutureWarning, match="Series.ceil and DataFrame.ceil are deprecated" - ): - sr = sr.ceil() - np.testing.assert_equal(sr.to_numpy(), np.ceil(arr)) - - -def test_series_floor(): - arr = np.random.random(100) * 100 - sr = Series(arr) - with pytest.warns( - FutureWarning, match="Series.floor and DataFrame.floor are deprecated" - ): - sr = sr.floor() - np.testing.assert_equal(sr.to_numpy(), np.floor(arr)) - - -@pytest.mark.parametrize("nelem", [1, 7, 8, 9, 32, 64, 128]) -def test_validity_ceil(nelem): - # Data - data = np.random.random(nelem) * 100 - mask = utils.random_bitmask(nelem) - bitmask = utils.expand_bits_to_bytes(mask)[:nelem] - sr = Series.from_masked_array(data, mask) - - # Result - with pytest.warns( - FutureWarning, match="Series.ceil and DataFrame.ceil are deprecated" - ): - res = sr.ceil() - - na_value = -100000 - got = res.fillna(na_value).to_numpy() - res_mask = np.asarray(bitmask, dtype=np.bool_)[: data.size] - - expect = np.ceil(data) - expect[~res_mask] = na_value - - # Check - print("expect") - print(expect) - print("got") - print(got) - - np.testing.assert_array_equal(expect, got) - - @pytest.mark.parametrize("mth", ["min", "max", "sum", "product"]) def test_series_pandas_methods(mth): np.random.seed(0)