Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
302 changes: 151 additions & 151 deletions python/cudf/cudf/core/accessors/string.py

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions python/cudf/cudf/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def factorize(
>>> codes
array([0, 1, 1])
>>> uniques
Index(['a', 'c'], dtype='object')
Index(['a', 'c'], dtype='str')

When ``use_na_sentinel=True`` (the default), missing values are indicated
in the `codes` with the sentinel value ``-1`` and missing values are not
Expand All @@ -68,7 +68,7 @@ def factorize(
>>> codes
array([ 0, -1, 1, 2, 0])
>>> uniques
Index(['b', 'a', 'c'], dtype='object')
Index(['b', 'a', 'c'], dtype='str')

If NA is in the values, and we want to include NA in the uniques of the
values, it can be achieved by setting ``use_na_sentinel=False``.
Expand Down Expand Up @@ -161,7 +161,7 @@ def unique(values):
>>> import pandas as pd
>>> cudf.unique(cudf.Series([pd.Timestamp("20160101"), pd.Timestamp("20160101")]))
0 2016-01-01
dtype: datetime64[ns]
dtype: datetime64[us]

>>> cudf.unique(
... cudf.Series(
Expand All @@ -174,7 +174,7 @@ def unique(values):
... )
0 2016-01-01 00:00:00-05:00
1 2016-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]
dtype: datetime64[us, US/Eastern]

>>> cudf.unique(
... cudf.Index(
Expand All @@ -185,7 +185,7 @@ def unique(values):
... ]
... )
... )
DatetimeIndex(['2016-01-01 00:00:00-05:00', '2016-01-03 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]')
DatetimeIndex(['2016-01-01 00:00:00-05:00', '2016-01-03 00:00:00-05:00'], dtype='datetime64[us, US/Eastern]')

An unordered Categorical will return categories in the
order of appearance.
Expand All @@ -195,14 +195,14 @@ def unique(values):
1 a
2 c
dtype: category
Categories (3, object): ['a', 'b', 'c']
Categories (3, str): ['a', 'b', 'c']

>>> cudf.unique(cudf.Series(pd.Categorical(list("baabc"), categories=list("abc"))))
0 b
1 a
2 c
dtype: category
Categories (3, object): ['a', 'b', 'c']
Categories (3, str): ['a', 'b', 'c']

An ordered Categorical preserves the category ordering.

Expand All @@ -215,7 +215,7 @@ def unique(values):
1 a
2 c
dtype: category
Categories (3, object): ['a' < 'b' < 'c']
Categories (3, str): ['a' < 'b' < 'c']
"""
# TODO: Avoid accessing Index and Series from the top level namespace
if not isinstance(values, (cudf.Series, cudf.Index, cp.ndarray)):
Expand Down
18 changes: 9 additions & 9 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,8 @@ class DataFrame(IndexedFrame, GetAttrGetItemMixin):
... ])
>>> df
0 1 2 3 4
0 5 cats jump <NA> None
1 2 dogs dig 7.5 None
0 5 cats jump <NA> NaN
1 2 dogs dig 7.5 NaN
2 3 cows moo -2.1 occasionally

Convert from a Pandas DataFrame:
Expand Down Expand Up @@ -6752,7 +6752,7 @@ def mode(self, axis=0, numeric_only=False, dropna=True):
>>> df.mode()
species legs wings
0 bird 2 0.0
1 None <NA> 2.0
1 NaN <NA> 2.0

Setting ``dropna=False``, ``NA`` values are considered and they can be
the mode (like for wings).
Expand Down Expand Up @@ -8549,7 +8549,7 @@ def from_pandas(obj, nan_as_null=no_default):
>>> type(gdf)
<class 'cudf.core.dataframe.DataFrame'>
>>> type(pdf)
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.DataFrame'>

Converting a Pandas Series to cuDF Series:

Expand All @@ -8559,18 +8559,18 @@ def from_pandas(obj, nan_as_null=no_default):
1 b
2 c
3 d
Name: apple, dtype: object
Name: apple, dtype: str
>>> gsr = cudf.from_pandas(psr)
>>> gsr
0 a
1 b
2 c
3 d
Name: apple, dtype: object
Name: apple, dtype: str
>>> type(gsr)
<class 'cudf.core.series.Series'>
>>> type(psr)
<class 'pandas.core.series.Series'>
<class 'pandas.Series'>

Converting a Pandas Index to cuDF Index:

Expand All @@ -8583,7 +8583,7 @@ def from_pandas(obj, nan_as_null=no_default):
>>> type(gidx)
<class 'cudf.core.index.Index'>
>>> type(pidx)
<class 'pandas.core.indexes.base.Index'>
<class 'pandas.Index'>

Converting a Pandas MultiIndex to cuDF MultiIndex:

Expand All @@ -8610,7 +8610,7 @@ def from_pandas(obj, nan_as_null=no_default):
>>> type(gmidx)
<class 'cudf.core.multiindex.MultiIndex'>
>>> type(pmidx)
<class 'pandas.core.indexes.multi.MultiIndex'>
<class 'pandas.MultiIndex'>
"""
if nan_as_null is no_default:
nan_as_null = False if get_option("mode.pandas_compatible") else None
Expand Down
12 changes: 6 additions & 6 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,9 @@ def isna(self) -> Self:
... 'toy': [None, 'Batmobile', 'Joker']})
>>> df
age born name toy
0 5 NaT Alfred None
1 6 1939-05-27 00:00:00.000000000 Batman Batmobile
2 <NA> 1940-04-25 00:00:00.000000000 Joker
0 5 NaT Alfred NaN
1 6 1939-05-27 00:00:00.000000 Batman Batmobile
2 <NA> 1940-04-25 00:00:00.000000 Joker
>>> df.isna()
age born name toy
0 False True False True
Expand Down Expand Up @@ -1326,9 +1326,9 @@ def notna(self) -> Self:
... 'toy': [None, 'Batmobile', 'Joker']})
>>> df
age born name toy
0 5 NaT Alfred None
1 6 1939-05-27 00:00:00.000000000 Batman Batmobile
2 <NA> 1940-04-25 00:00:00.000000000 Joker
0 5 NaT Alfred NaN
1 6 1939-05-27 00:00:00.000000 Batman Batmobile
2 <NA> 1940-04-25 00:00:00.000000 Joker
>>> df.notna()
age born name toy
0 True False True False
Expand Down
10 changes: 5 additions & 5 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3948,7 +3948,7 @@ def day_name(self, locale: str | None = None) -> Index:
DatetimeIndex(['2016-12-31', '2017-01-01', '2017-01-02', '2017-01-03',
'2017-01-04', '2017-01-05', '2017-01-06', '2017-01-07',
'2017-01-08'],
dtype='datetime64[ns]', freq='24h')
dtype='datetime64[us]', freq='24h')
>>> datetime_index.day_name()
Index(['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday', 'Sunday'],
Expand All @@ -3969,7 +3969,7 @@ def month_name(self, locale: str | None = None) -> Index:
>>> datetime_index
DatetimeIndex(['2017-12-30', '2018-01-06', '2018-01-13', '2018-01-20',
'2018-01-27', '2018-02-03'],
dtype='datetime64[ns]', freq='168h')
dtype='datetime64[us]', freq='168h')
>>> datetime_index.month_name()
Index(['December', 'January', 'January', 'January', 'January', 'February'], dtype='str')
"""
Expand Down Expand Up @@ -4139,7 +4139,7 @@ def tz_localize(
>>> tz_aware
DatetimeIndex(['2018-03-01 09:00:00-05:00', '2018-03-02 09:00:00-05:00',
'2018-03-03 09:00:00-05:00'],
dtype='datetime64[ns, America/New_York]', freq='24h')
dtype='datetime64[us, America/New_York]', freq='24h')

Ambiguous or nonexistent datetimes are converted to NaT.

Expand Down Expand Up @@ -4189,12 +4189,12 @@ def tz_convert(self, tz: str | None) -> Self:
>>> dti
DatetimeIndex(['2018-03-01 09:00:00-05:00', '2018-03-02 09:00:00-05:00',
'2018-03-03 09:00:00-05:00'],
dtype='datetime64[ns, America/New_York]', freq='24h')
dtype='datetime64[us, America/New_York]', freq='24h')
>>> dti.tz_convert("Europe/London")
DatetimeIndex(['2018-03-01 14:00:00+00:00',
'2018-03-02 14:00:00+00:00',
'2018-03-03 14:00:00+00:00'],
dtype='datetime64[ns, Europe/London]')
dtype='datetime64[us, Europe/London]')
"""
result_col = self._column.tz_convert(tz)
return DatetimeIndex._from_column(result_col, name=self.name)
Expand Down
48 changes: 24 additions & 24 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,14 @@ def replace(
2 a
3 b
4 a
dtype: object
dtype: str
>>> s.replace({'a': None})
0 b
1 None
2 None
1 NaN
2 NaN
3 b
4 None
dtype: object
4 NaN
dtype: str

If there is a mismatch in types of the values in
``to_replace`` & ``value`` with the actual series, then
Expand All @@ -794,15 +794,15 @@ def replace(
2 a
3 b
4 a
dtype: object
dtype: str
>>> s.replace('a', 1)
Traceback (most recent call last):
...
TypeError: to_replace and value should be of same types,got to_replace dtype: object and value dtype: int64
TypeError: to_replace and value should be of same types,got to_replace dtype: str and value dtype: int64
>>> s.replace(['a', 'c'], [1, 2])
Traceback (most recent call last):
...
TypeError: to_replace and value should be of same types,got to_replace dtype: object and value dtype: int64
TypeError: to_replace and value should be of same types,got to_replace dtype: str and value dtype: int64

**DataFrame**

Expand Down Expand Up @@ -1213,7 +1213,7 @@ def head(self, n=5):
6 shark
7 whale
8 zebra
dtype: object
dtype: str

Viewing the first 5 lines

Expand All @@ -1223,15 +1223,15 @@ def head(self, n=5):
2 falcon
3 lion
4 monkey
dtype: object
dtype: str

Viewing the first `n` lines (three in this case)

>>> ser.head(3)
0 alligator
1 bee
2 falcon
dtype: object
dtype: str

For negative values of `n`

Expand All @@ -1242,7 +1242,7 @@ def head(self, n=5):
3 lion
4 monkey
5 parrot
dtype: object
dtype: str

**DataFrame**

Expand Down Expand Up @@ -2655,13 +2655,13 @@ def sort_index(
2 b
1 c
4 d
dtype: object
dtype: str
>>> series.sort_index()
1 c
2 b
3 a
4 d
dtype: object
dtype: str

Sort Descending

Expand All @@ -2670,7 +2670,7 @@ def sort_index(
3 a
2 b
1 c
dtype: object
dtype: str

**DataFrame**

Expand Down Expand Up @@ -2833,7 +2833,7 @@ def hash_values(
0 7be4bbacbfdb05fb3044e36c22b41e8b
1 947ca8d2c5f0f27437f156cfbfab0969
2 d0580ef52d27c043c8e341fd5039b166
dtype: object
dtype: str
>>> series.hash_values(method="murmur3", seed=42)
0 4279022973
1 1654398277
Expand All @@ -2858,7 +2858,7 @@ def hash_values(
0 57ce879751b5169c525907d5c563fae1
1 948d6221a7c4963d4be411bcead7e32b
2 fe061786ea286a515b772d91b0dfcd70
dtype: object
dtype: str
"""
seed_hash_methods = {"murmur3", "xxhash32", "xxhash64"}
if seed is None:
Expand Down Expand Up @@ -4088,7 +4088,7 @@ def resample(
--------
First, we create a time series with 1 minute intervals:

>>> index = cudf.date_range(start="2001-01-01", periods=10, freq="1T")
>>> index = cudf.date_range(start="2001-01-01", periods=10, freq="1min")
>>> sr = cudf.Series(range(10), index=index)
>>> sr
2001-01-01 00:00:00 0
Expand All @@ -4105,7 +4105,7 @@ def resample(

Downsampling to 3 minute intervals, followed by a "sum" aggregation:

>>> sr.resample("3T").sum()
>>> sr.resample("3min").sum()
2001-01-01 00:00:00 3
2001-01-01 00:03:00 12
2001-01-01 00:06:00 21
Expand All @@ -4114,7 +4114,7 @@ def resample(

Use the right side of each interval to label the bins:

>>> sr.resample("3T", label="right").sum()
>>> sr.resample("3min", label="right").sum()
2001-01-01 00:03:00 3
2001-01-01 00:06:00 12
2001-01-01 00:09:00 21
Expand All @@ -4123,7 +4123,7 @@ def resample(

Close the right side of the interval instead of the left:

>>> sr.resample("3T", closed="right").sum()
>>> sr.resample("3min", closed="right").sum()
2000-12-31 23:57:00 0
2001-01-01 00:00:00 6
2001-01-01 00:03:00 15
Expand Down Expand Up @@ -4268,7 +4268,7 @@ def dropna(
>>> df
name toy born
0 Alfred Batmobile 1940-04-25 00:00:00.000000000
1 Batman None NaT
1 Batman NaN NaT
2 Catwoman Bullwhip NaT

Drop the rows where at least one element is null.
Expand All @@ -4290,7 +4290,7 @@ def dropna(
>>> df.dropna(how='all')
name toy born
0 Alfred Batmobile 1940-04-25 00:00:00.000000000
1 Batman None NaT
1 Batman NaN NaT
2 Catwoman Bullwhip NaT

Keep only the rows with at least 2 non-null values.
Expand Down Expand Up @@ -4460,7 +4460,7 @@ def take(self, indices, axis=0):
0 a
4 e
3 d
dtype: object
dtype: str

**DataFrame**

Expand Down
Loading
Loading