diff --git a/AUTHORS.md b/AUTHORS.md index b59812dad..5ac040b07 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -112,3 +112,4 @@ Contributors - [@asmirnov69](https://github.com/asmirnov69) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%asmirnov69) - [@xujiboy](https://github.com/xujiboy) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%xujiboy) - [@joranbeasley](https://github.com/joranbeasley) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%joranbeasley) +- [@Fu-Jie](https://github.com/Fu-Jie) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/pulls?q=is%3Aclosed+mentions%3AFu-Jie) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e46020f..788282a46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [INF] Replace `pytest.ini` file with `pyproject.toml` file. PR #1204 @Zeroto521 - [INF] Extract docstrings tests from all tests. PR #1205 @Zeroto521 - [BUG] address the `TypeError` when importing v0.24.0 (issue #1201 @xujiboy and @joranbeasley) +- [BUG] Modify ignore_empty output in `concatenate_columns`. Issue #1164 @Fu-Jie ## [v0.24.0] - 2022-11-12 diff --git a/janitor/functions/concatenate_columns.py b/janitor/functions/concatenate_columns.py index 757b7a715..5772658b8 100644 --- a/janitor/functions/concatenate_columns.py +++ b/janitor/functions/concatenate_columns.py @@ -51,8 +51,9 @@ def concatenate_columns( if len(column_names) < 2: raise JanitorError("At least two columns must be specified") + df = df.copy() # avoid mutating original data df[new_column_name] = ( - df[column_names].astype(str).fillna("").agg(sep.join, axis=1) + df[column_names].astype("string").fillna("").agg(sep.join, axis=1) ) if ignore_empty: diff --git a/tests/functions/test_concatenate_columns.py b/tests/functions/test_concatenate_columns.py index 25a7d7bee..341fb344d 100644 --- a/tests/functions/test_concatenate_columns.py +++ b/tests/functions/test_concatenate_columns.py @@ -28,7 +28,7 @@ def test_concatenate_columns_null_values(missingdata_df): new_column_name="index", ignore_empty=True, ) - expected_values = ["1.0-1", "2.0-2", "nan-3"] * 3 + expected_values = ["1.0-1", "2.0-2", "3"] * 3 assert expected_values == df["index"].tolist()