Skip to content

Commit

Permalink
🐛 update to make it pandas 2 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry committed May 14, 2024
1 parent 9d4fd08 commit 12f19c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = njab
version = 0.0.5
version = 0.0.6
description = not Just Another Biomarker
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
8 changes: 3 additions & 5 deletions src/njab/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ def combine_value_counts(X: pd.DataFrame, dropna=True) -> pd.DataFrame:
pandas.DataFrame
DataFrame of combined value counts.
"""
"""
"""
_df = pd.DataFrame()
freq_targets = list()
for col in X.columns:
_df = _df.join(X[col].value_counts(dropna=dropna), how='outer')
freq_targets = _df.sort_index()
freq_targets.append(X[col].value_counts(dropna=dropna).rename(col))
freq_targets = pd.concat(freq_targets, axis=1, sort=True)
return freq_targets
8 changes: 8 additions & 0 deletions test/test_pandas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import pandas as pd

import njab


def test_thousands_display():
njab.pandas.set_pandas_options()
s = pd.Series([1_000_000])
assert str(s)[4:13] == '1,000,000'


def test_combine_value_counts():
df = pd.DataFrame({'a': [1, 2, 2, 2, 3, 3, 3], 'b': [1, 1, 1, 2, 2, 3, 3]})
exp = {'a': {1: 1, 2: 3, 3: 3}, 'b': {1: 3, 2: 2, 3: 2}}
act = njab.pandas.combine_value_counts(df).to_dict()
assert act == exp

0 comments on commit 12f19c5

Please sign in to comment.