Skip to content

[EHN] Set expand_column's sep default as "|" #880

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
merged 8 commits into from
Aug 19, 2021
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ Contributors
- `@MollyCroke <https://github.com/MollyCroke>`_ | `contributions <https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3AMollyCroke>`_
- `@ericclessantostv <https://github.com/ericlessantostv>`_ | `contributions <https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Aericclessantostv>`_
- `@fireddd <https://github.com/fireddd>`_ | `contributions <https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Afireddd>`_
- `@Zeroto521 <https://github.com/Zeroto521>`_ | `contributions <https://github.com/pyjanitor-devs/pyjanitor/pulls?utf8=%E2%9C%93&q=is%3Aclosed+mentions%3Zeroto521>`_
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [Unreleased]

- [DOC] Fix references and broken links in AUTHORS.rst. @loganthomas
- [DOC] Updated Broken links in the README and contributing docs. @nvamsikrishna05
- [INF] Update pre-commit hooks and remove mutable references. Issue #844. @loganthomas
Expand All @@ -14,6 +15,7 @@
- [DOC] Delete Read the Docs project and remove all readthedocs.io references from the repo. Issue #863. @loganthomas
- [DOC] Updated various documentation sources to reflect pyjanitor-dev ownership. @loganthomas
- [INF] Fix `isort` automatic checks. Issue #845. @loganthomas
- [EHN] Set `expand_column`'s `sep` default is `"|"`, same to `pandas.Series.str.get_dummies`. Issue #876. @Zeroto521
- [ENH] Deprecate `limit` from fill_direction. fill_direction now uses kwargs. @samukweku

## [v0.21.0] - 2021-07-16
Expand Down
8 changes: 6 additions & 2 deletions janitor/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,10 @@ def _fill_empty(df, column_names, value=None): # noqa: F811
@pf.register_dataframe_method
@deprecated_alias(column="column_name")
def expand_column(
df: pd.DataFrame, column_name: Hashable, sep: str, concat: bool = True
df: pd.DataFrame,
column_name: Hashable,
sep: str = "|",
concat: bool = True,
) -> pd.DataFrame:
"""Expand a categorical column with multiple labels into dummy-coded columns.

Expand All @@ -1319,7 +1322,8 @@ def expand_column(

:param df: A pandas DataFrame.
:param column_name: Which column to expand.
:param sep: The delimiter. Example delimiters include `|`, `, `, `,` etc.
:param sep: The delimiter, same to
:py:meth:`~pandas.Series.str.get_dummies`'s `sep`, default as `|`.
:param concat: Whether to return the expanded column concatenated to
the original dataframe (`concat=True`), or to return it standalone
(`concat=False`).
Expand Down
14 changes: 14 additions & 0 deletions tests/functions/test_expand_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ def test_expand_and_concat():
column_name="col1", sep=", ", concat=True
)
assert df.shape[1] == 8


@pytest.mark.functions
def test_sep_default_parameter():
"""Test that the default parameter is a pipe character `|`."""
df = pd.DataFrame(
{
"col1": ["A|B", "B|C|D", "E|F", "A|E|F"],
"col2": [1, 2, 3, 4],
}
)
result = df.expand_column("col1")

assert result.shape[1] == 8