Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ceil/floor for DatetimeIndex #9554

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
69c3c87
Add initial file from `DataFrame.rst` as template
mayankanand007 Oct 1, 2021
9a8e65f
Added docs for `SubwordTokenizer`
mayankanand007 Oct 1, 2021
3fbf0eb
Merge branch 'rapidsai:branch-21.12' into branch-21.12
mayankanand007 Oct 1, 2021
0a7472a
Update subword_tokenize.rst
mayankanand007 Oct 1, 2021
415dbd3
Update subword_tokenize.rst
mayankanand007 Oct 1, 2021
b6de7a7
Added `subword_tokenize` entry in the index
mayankanand007 Oct 1, 2021
d42ab31
Merge branch 'rapidsai:branch-21.12' into branch-21.12
mayankanand007 Oct 28, 2021
c91831f
Merge branch 'rapidsai:branch-21.12' into branch-21.12
mayankanand007 Oct 28, 2021
93bc413
added initial changes
mayankanand007 Oct 28, 2021
1f77dd4
added floor/ceil with DatetimeIndex
mayankanand007 Oct 28, 2021
bcddcde
added docs for floor/ceil
mayankanand007 Oct 28, 2021
937f7b4
fixed style issues
mayankanand007 Oct 28, 2021
74e2b0e
added python tests
mayankanand007 Oct 29, 2021
d854685
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Oct 29, 2021
0eb4f1c
added python tests
mayankanand007 Oct 29, 2021
9b07327
Merge branch 'datetimeindex_ceil_floor' of https://github.com/mayanka…
mayankanand007 Oct 29, 2021
e7bcc7b
fixed return arg
mayankanand007 Oct 29, 2021
42be0c9
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Oct 29, 2021
7e6e530
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Nov 1, 2021
2c97aa5
added depr. warnings
mayankanand007 Nov 1, 2021
f64fbf6
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Nov 1, 2021
1c3decc
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Nov 2, 2021
b790eac
added floor test
mayankanand007 Nov 2, 2021
336255b
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Nov 2, 2021
eab4ecc
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Nov 8, 2021
b92d01e
Merge branch 'rapidsai:branch-21.12' into datetimeindex_ceil_floor
mayankanand007 Nov 10, 2021
f2c3d1f
addressing some reviews
mayankanand007 Nov 10, 2021
b3b8684
parametrizing test cases
mayankanand007 Nov 10, 2021
2f56beb
fixed docs issues
mayankanand007 Nov 10, 2021
8cecc40
Merge branch 'rapidsai:branch-22.02' into datetimeindex_ceil_floor
mayankanand007 Nov 16, 2021
2c7274f
Merge branch 'rapidsai:branch-22.02' into datetimeindex_ceil_floor
mayankanand007 Nov 16, 2021
ead7eae
Merge branch 'rapidsai:branch-22.02' into datetimeindex_ceil_floor
mayankanand007 Nov 17, 2021
b8ff1b4
modify warning message
mayankanand007 Nov 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/cudf/source/api_docs/index_objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ Time-specific operations
:toctree: api/

DatetimeIndex.round
DatetimeIndex.ceil
DatetimeIndex.floor

Conversion
~~~~~~~~~~
Expand Down
14 changes: 14 additions & 0 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3673,6 +3673,13 @@ def ceil(self):
3 5.0
dtype: float64
"""

warnings.warn(
"Series.ceil and DataFrame.ceil are deprecated and will be \
removed in the future",
DeprecationWarning,
)

return self._unaryop("ceil")

def floor(self):
Expand Down Expand Up @@ -3705,6 +3712,13 @@ def floor(self):
5 3.0
dtype: float64
"""

warnings.warn(
"Series.ceil and DataFrame.ceil are deprecated and will be \
removed in the future",
DeprecationWarning,
)

return self._unaryop("floor")

def scale(self):
Expand Down
62 changes: 62 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,68 @@ def _get_dt_field(self, field):
def is_boolean(self):
return False

def ceil(self, field):
"""
Perform ceil operation on the data to the specified freq.
Parameters
----------
field : str
One of ["D", "H", "T", "min", "S", "L", "ms", "U", "us", "N"].
Must be a fixed frequency like 'S' (second) not 'ME' (month end).
See `frequency aliases <https://pandas.pydata.org/docs/\
user_guide/timeseries.html#timeseries-offset-aliases>`__
for more details on these aliases.
Returns
-------
DatetimeIndex
Index of the same type for a DatetimeIndex
Examples
--------
>>> import cudf
>>> gIndex = cudf.DatetimeIndex(["2020-05-31 08:00:00",
... "1999-12-31 18:40:00"])
>>> gIndex.ceil("T")
DatetimeIndex(['2020-05-31 08:00:00', '1999-12-31 18:40:00'],
dtype='datetime64[ns]', freq=None)
"""
out_column = self._values.ceil(field)

return self.__class__._from_data({self.name: out_column})

def floor(self, field):
"""
Perform floor operation on the data to the specified freq.
Parameters
----------
field : str
One of ["D", "H", "T", "min", "S", "L", "ms", "U", "us", "N"].
Must be a fixed frequency like 'S' (second) not 'ME' (month end).
See `frequency aliases <https://pandas.pydata.org/docs/\
user_guide/timeseries.html#timeseries-offset-aliases>`__
for more details on these aliases.
Returns
-------
DatetimeIndex
Index of the same type for a DatetimeIndex
Examples
--------
>>> import cudf
>>> gIndex = cudf.DatetimeIndex(["2020-05-31 08:59:59"
... ,"1999-12-31 18:44:59"])
>>> gIndex.floor("T")
DatetimeIndex(['2020-05-31 08:59:00', '1999-12-31 18:44:00'],
dtype='datetime64[ns]', freq=None)
"""
out_column = self._values.floor(field)

return self.__class__._from_data({self.name: out_column})


class TimedeltaIndex(GenericIndex):
"""
Expand Down
26 changes: 26 additions & 0 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2470,3 +2470,29 @@ def test_index_type_methods(data, func):
assert_eq(False, actual)
else:
assert_eq(expected, actual)


@pytest.mark.parametrize(
"resolution", ["D", "H", "T", "min", "S", "L", "ms", "U", "us", "N"]
)
def test_index_datetime_ceil(resolution):
shwina marked this conversation as resolved.
Show resolved Hide resolved
cuidx = cudf.DatetimeIndex([1000000, 2000000, 3000000, 4000000, 5000000])
pidx = cuidx.to_pandas()

pidx_ceil = pidx.ceil(resolution)
cuidx_ceil = cuidx.ceil(resolution)

assert_eq(pidx_ceil, cuidx_ceil)


@pytest.mark.parametrize(
"resolution", ["D", "H", "T", "min", "S", "L", "ms", "U", "us", "N"]
)
def test_index_datetime_floor(resolution):
cuidx = cudf.DatetimeIndex([1000000, 2000000, 3000000, 4000000, 5000000])
pidx = cuidx.to_pandas()

pidx_floor = pidx.floor(resolution)
cuidx_floor = cuidx.floor(resolution)

assert_eq(pidx_floor, cuidx_floor)