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 f2fb381
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/njab/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def combine_value_counts(X: pd.DataFrame, dropna=True) -> pd.DataFrame:
"""
"""
"""
_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))
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 f2fb381

Please sign in to comment.