Skip to content

Commit 44ae1fe

Browse files
authored
[DOC] Convert docstring example to doctest for expand_column() (pyjanitor-devs#1071)
1 parent db0281c commit 44ae1fe

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

Diff for: AUTHORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ Contributors
103103
- [@Zeroto521](https://github.com/Zeroto521) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/pulls?utf8=%E2%9C%93&q=is%3Aclosed+mentions%3Zeroto521)
104104
- [@thatlittleboy](https://github.com/thatlittleboy) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Athatlittleboy)
105105
- [@robertmitchellv](https://github.com/robertmitchellv) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Arobertmitchellv)
106+
- [@gahjelle](https://github.com/gahjelle) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Agahjelle)

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [BUG] Fixed bug in `transform_columns` which ignored the `column_names` specification when `new_column_names` dictionary was provided as an argument, issue #1063. @thatlittleboy
2727
- [BUG] `count_cumulative_unique` no longer modifies the column being counted in the output when `case_sensitive` argument is set to False, issue #1065. @thatlittleboy
2828
- [BUG] Fix for gcc missing error in dev container
29+
- [DOC] Convert `expand_column` code examples to doctests, issue #972. @gahjelle
2930

3031
## [v0.22.0] - 2021-11-21
3132

Diff for: janitor/functions/expand_column.py

+41-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
"""Implementation for expand_column."""
12
from typing import Hashable
2-
import pandas_flavor as pf
3+
34
import pandas as pd
5+
import pandas_flavor as pf
46

57
from janitor.utils import deprecated_alias
68

@@ -21,23 +23,47 @@ def expand_column(
2123
2224
Functional usage syntax:
2325
24-
df = expand_column(
25-
df,
26-
column_name='col_name',
27-
sep=', ' # note space in sep
28-
)
26+
>>> import pandas as pd
27+
>>> df = pd.DataFrame(
28+
... {
29+
... "col1": ["A, B", "B, C, D", "E, F", "A, E, F"],
30+
... "col2": [1, 2, 3, 4],
31+
... }
32+
... )
33+
>>> df = expand_column(
34+
... df,
35+
... column_name="col1",
36+
... sep=", " # note space in sep
37+
... )
38+
>>> df
39+
col1 col2 A B C D E F
40+
0 A, B 1 1 1 0 0 0 0
41+
1 B, C, D 2 0 1 1 1 0 0
42+
2 E, F 3 0 0 0 0 1 1
43+
3 A, E, F 4 1 0 0 0 1 1
2944
3045
Method chaining syntax:
3146
32-
import pandas as pd
33-
import janitor
34-
df = (
35-
pd.DataFrame(...)
36-
.expand_column(
37-
column_name='col_name',
38-
sep=', '
39-
)
40-
)
47+
>>> import pandas as pd
48+
>>> import janitor
49+
>>> df = (
50+
... pd.DataFrame(
51+
... {
52+
... "col1": ["A, B", "B, C, D", "E, F", "A, E, F"],
53+
... "col2": [1, 2, 3, 4],
54+
... }
55+
... )
56+
... .expand_column(
57+
... column_name='col1',
58+
... sep=', '
59+
... )
60+
... )
61+
>>> df
62+
col1 col2 A B C D E F
63+
0 A, B 1 1 1 0 0 0 0
64+
1 B, C, D 2 0 1 1 1 0 0
65+
2 E, F 3 0 0 0 0 1 1
66+
3 A, E, F 4 1 0 0 0 1 1
4167
4268
:param df: A pandas DataFrame.
4369
:param column_name: Which column to expand.

0 commit comments

Comments
 (0)