Skip to content

DOC: fix doctests for string dtype changes (top-level) #61887

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

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
10 changes: 5 additions & 5 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,28 +794,28 @@ def categories(self) -> Index:

>>> ser = pd.Series(["a", "b", "c", "a"], dtype="category")
>>> ser.cat.categories
Index(['a', 'b', 'c'], dtype='object')
Index(['a', 'b', 'c'], dtype='str')

>>> raw_cat = pd.Categorical(["a", "b", "c", "a"], categories=["b", "c", "d"])
>>> ser = pd.Series(raw_cat)
>>> ser.cat.categories
Index(['b', 'c', 'd'], dtype='object')
Index(['b', 'c', 'd'], dtype='str')

For :class:`pandas.Categorical`:

>>> cat = pd.Categorical(["a", "b"], ordered=True)
>>> cat.categories
Index(['a', 'b'], dtype='object')
Index(['a', 'b'], dtype='str')

For :class:`pandas.CategoricalIndex`:

>>> ci = pd.CategoricalIndex(["a", "c", "b", "a", "c", "b"])
>>> ci.categories
Index(['a', 'b', 'c'], dtype='object')
Index(['a', 'b', 'c'], dtype='str')

>>> ci = pd.CategoricalIndex(["a", "c"], categories=["c", "b", "a"])
>>> ci.categories
Index(['c', 'b', 'a'], dtype='object')
Index(['c', 'b', 'a'], dtype='str')
"""
return self.dtype.categories

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def categories(self) -> Index:
--------
>>> cat_type = pd.CategoricalDtype(categories=["a", "b"], ordered=True)
>>> cat_type.categories
Index(['a', 'b'], dtype='object')
Index(['a', 'b'], dtype='str')
"""
return self._categories

Expand Down
12 changes: 6 additions & 6 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def isna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame:
>>> df = pd.DataFrame([["ant", "bee", "cat"], ["dog", None, "fly"]])
>>> df
0 1 2
0 ant bee cat
1 dog None fly
0 1 2
0 ant bee cat
1 dog NaN fly
>>> pd.isna(df)
0 1 2
0 False False False
Expand Down Expand Up @@ -373,9 +373,9 @@ def notna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame:
>>> df = pd.DataFrame([["ant", "bee", "cat"], ["dog", None, "fly"]])
>>> df
0 1 2
0 ant bee cat
1 dog None fly
0 1 2
0 ant bee cat
1 dog NaN fly
>>> pd.notna(df)
0 1 2
0 True True True
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,7 @@ def axes(self) -> list[Index]:
--------
>>> df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
>>> df.axes
[RangeIndex(start=0, stop=2, step=1), Index(['col1', 'col2'],
dtype='object')]
[RangeIndex(start=0, stop=2, step=1), Index(['col1', 'col2'], dtype='str')]
"""
return [self.index, self.columns]

Expand Down Expand Up @@ -14070,7 +14069,7 @@ def values(self) -> np.ndarray:
... columns=("name", "max_speed", "rank"),
... )
>>> df2.dtypes
name object
name str
max_speed float64
rank object
dtype: object
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4628,13 +4628,13 @@ def ngroup(self, ascending: bool = True):
--------
>>> df = pd.DataFrame({"color": ["red", None, "red", "blue", "blue", "red"]})
>>> df
color
0 red
1 None
2 red
3 blue
4 blue
5 red
color
0 red
1 NaN
2 red
3 blue
4 blue
5 red
>>> df.groupby("color").ngroup()
0 1.0
1 NaN
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class Index(IndexOpsMixin, PandasObject):
Index([1, 2, 3], dtype='int64')

>>> pd.Index(list("abc"))
Index(['a', 'b', 'c'], dtype='object')
Index(['a', 'b', 'c'], dtype='str')

>>> pd.Index([1, 2, 3], dtype="uint8")
Index([1, 2, 3], dtype='uint8')
Expand Down Expand Up @@ -7599,7 +7599,7 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
Examples
--------
>>> ensure_index(["a", "b"])
Index(['a', 'b'], dtype='object')
Index(['a', 'b'], dtype='str')

>>> ensure_index([("a", "a"), ("b", "c")])
Index([('a', 'a'), ('b', 'c')], dtype='object')
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/interchange/from_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def from_dataframe(df, allow_copy: bool = True) -> pd.DataFrame:
>>> df_not_necessarily_pandas = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
>>> interchange_object = df_not_necessarily_pandas.__dataframe__()
>>> interchange_object.column_names()
Index(['A', 'B'], dtype='object')
Index(['A', 'B'], dtype='str')
>>> df_pandas = pd.api.interchange.from_dataframe(
... interchange_object.select_columns_by_name(["A"])
... )
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def concat(
1 b
0 c
1 d
dtype: object
dtype: str

Clear the existing index and reset it in the result
by setting the ``ignore_index`` option to ``True``.
Expand All @@ -268,7 +268,7 @@ def concat(
1 b
2 c
3 d
dtype: object
dtype: str

Add a hierarchical index at the outermost level of
the data with the ``keys`` option.
Expand All @@ -278,7 +278,7 @@ def concat(
1 b
s2 0 c
1 d
dtype: object
dtype: str

Label the index keys you create with the ``names`` option.

Expand All @@ -288,7 +288,7 @@ def concat(
1 b
s2 0 c
1 d
dtype: object
dtype: str

Combine two ``DataFrame`` objects with identical columns.

Expand Down
Loading