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 24 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
12 changes: 12 additions & 0 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3661,6 +3661,12 @@ def ceil(self):
3 5.0
dtype: float64
"""

warnings.warn(
"Series.ceil is deprecated and will be removed in the future",
mayankanand007 marked this conversation as resolved.
Show resolved Hide resolved
DeprecationWarning,
)

return self._unaryop("ceil")

def floor(self):
Expand Down Expand Up @@ -3693,6 +3699,12 @@ def floor(self):
5 3.0
dtype: float64
"""

warnings.warn(
"Series.floor is deprecated and will be removed in the future",
DeprecationWarning,
)

return self._unaryop("floor")

def scale(self):
Expand Down
74 changes: 74 additions & 0 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,80 @@ 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", "S", "L", "U", "N"]
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)

out_column = column.build_column(
data=out_column.base_data,
dtype=out_column.dtype,
mask=out_column.base_mask,
offset=out_column.offset,
)

return as_index(out_column, name=self.name)

def floor(self, field):
"""
Perform floor operation on the data to the specified freq.

Parameters
----------
field : str
One of ["D", "H", "T", "S", "L", "U", "N"]
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)

out_column = column.build_column(
data=out_column.base_data,
dtype=out_column.dtype,
mask=out_column.base_mask,
offset=out_column.offset,
)
mayankanand007 marked this conversation as resolved.
Show resolved Hide resolved

return as_index(out_column, name=self.name)
mayankanand007 marked this conversation as resolved.
Show resolved Hide resolved


class TimedeltaIndex(GenericIndex):
"""
Expand Down
20 changes: 20 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,23 @@ def test_index_type_methods(data, func):
assert_eq(False, actual)
else:
assert_eq(expected, actual)


def test_index_datetime_ceil():
cuidx = cudf.DatetimeIndex([1000000, 2000000, 3000000, 4000000, 5000000])
pidx = cuidx.to_pandas()

pidx_ceil = pidx.ceil("T")
cuidx_ceil = cuidx.ceil("T")
mayankanand007 marked this conversation as resolved.
Show resolved Hide resolved

assert_eq(pidx_ceil, cuidx_ceil)


def test_index_datetime_floor():
cuidx = cudf.DatetimeIndex([1000000, 2000000, 3000000, 4000000, 5000000])
pidx = cuidx.to_pandas()

pidx_floor = pidx.floor("T")
cuidx_floor = cuidx.floor("T")

assert_eq(pidx_floor, cuidx_floor)