Skip to content

Commit 12f19c5

Browse files
author
Henry
committed
🐛 update to make it pandas 2 compatible
1 parent 9d4fd08 commit 12f19c5

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = njab
3-
version = 0.0.5
3+
version = 0.0.6
44
description = not Just Another Biomarker
55
long_description = file: README.md
66
long_description_content_type = text/markdown

src/njab/pandas/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ def combine_value_counts(X: pd.DataFrame, dropna=True) -> pd.DataFrame:
120120
pandas.DataFrame
121121
DataFrame of combined value counts.
122122
"""
123-
"""
124-
"""
125-
_df = pd.DataFrame()
123+
freq_targets = list()
126124
for col in X.columns:
127-
_df = _df.join(X[col].value_counts(dropna=dropna), how='outer')
128-
freq_targets = _df.sort_index()
125+
freq_targets.append(X[col].value_counts(dropna=dropna).rename(col))
126+
freq_targets = pd.concat(freq_targets, axis=1, sort=True)
129127
return freq_targets

test/test_pandas.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import pandas as pd
2+
23
import njab
34

45

56
def test_thousands_display():
67
njab.pandas.set_pandas_options()
78
s = pd.Series([1_000_000])
89
assert str(s)[4:13] == '1,000,000'
10+
11+
12+
def test_combine_value_counts():
13+
df = pd.DataFrame({'a': [1, 2, 2, 2, 3, 3, 3], 'b': [1, 1, 1, 2, 2, 3, 3]})
14+
exp = {'a': {1: 1, 2: 3, 3: 3}, 'b': {1: 3, 2: 2, 3: 2}}
15+
act = njab.pandas.combine_value_counts(df).to_dict()
16+
assert act == exp

0 commit comments

Comments
 (0)