Skip to content

Commit 0f98b88

Browse files
[BUG] Extend fill_empty's column_names type range (#1014)
* [BUG] Extend `fill_empty`'s `column_names` type range * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update CHANGELOG.md * update comment Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d3146bb commit 0f98b88

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [ENH] Add `xlsx_table`, for reading tables from an Excel sheet. @samukweku
1111
- [ENH] minor improvements for conditional_join; equality only joins are no longer supported; there has to be at least one non-equi join present. @samukweku
1212
- [BUG] `sort_column_value_order` no longer mutates original dataframe.
13+
- [BUG] Extend `fill_empty`'s `column_names` type range. Issue #998. @Zeroto521
1314

1415
## [v0.22.0] - 2021-11-21
1516

janitor/functions/fill.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections.abc import Iterable as abcIterable
12
from enum import Enum
23
from operator import methodcaller
34
from typing import Hashable, Iterable, Union
@@ -145,7 +146,7 @@ def fill_empty(
145146
return _fill_empty(df, column_names, value=value)
146147

147148

148-
@dispatch(pd.DataFrame, (list, tuple))
149+
@dispatch(pd.DataFrame, abcIterable)
149150
def _fill_empty(df, column_names, value=None):
150151
"""Fill empty function for the case that column_names is list or tuple."""
151152
fill_mapping = {c: value for c in column_names}

tests/functions/test_fill_empty.py

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import pandas as pd
23

34

45
@pytest.mark.functions
@@ -11,3 +12,22 @@ def test_fill_empty(null_df):
1112
def test_fill_empty_column_string(null_df):
1213
df = null_df.fill_empty(column_names="2", value=3)
1314
assert set(df.loc[:, "2"]) == set([3])
15+
16+
17+
@pytest.mark.functions
18+
@pytest.mark.parametrize(
19+
"column_names",
20+
[
21+
(0, 1, "2", "3"), # tuple
22+
[0, 1, "2", "3"], # list
23+
{0, 1, "2", "3"}, # set
24+
({0: 0, 1: 1, "2": "2", "3": "3"}).keys(), # dict key
25+
({0: 0, 1: 1, "2": "2", "3": "3"}).values(), # dict value
26+
pd.Index([0, 1, "2", "3"]), # Index
27+
],
28+
)
29+
def test_column_names_iterable_type(null_df, column_names):
30+
result = null_df.fill_empty(column_names=column_names, value=3)
31+
excepted = null_df.fillna(3)
32+
33+
assert result.equals(excepted)

0 commit comments

Comments
 (0)