Skip to content

coorectly infer boolean stypes #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added

- Added support for inferring `stype.categorical` from boolean columns in `utils.infer_series_stype` ([#421](https://github.com/pyg-team/pytorch-frame/pull/421))

### Changed

### Deprecated
Expand Down
7 changes: 6 additions & 1 deletion test/utils/test_infer_stype.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_infer_df_stype(with_nan):
assert col_to_stype_inferred == dataset.col_to_stype


def test_infer_multicategorical_stype():
def test_infer_stypes():
# Test when multicategoricals are lists
df = pd.DataFrame({
'category': [['Books', 'Mystery, Thriller'],
Expand All @@ -52,3 +52,8 @@ def test_infer_multicategorical_stype():
})
col_to_stype_inferred = infer_df_stype(df)
assert col_to_stype_inferred['category'] == torch_frame.multicategorical

df = pd.DataFrame({'bool': [True] * 50 + [False] * 50})

col_to_stype_inferred = infer_df_stype(df)
assert col_to_stype_inferred['bool'] == torch_frame.categorical
3 changes: 3 additions & 0 deletions torch_frame/utils/infer_stype.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def infer_series_stype(ser: Series) -> stype | None:
# text_(embedded/tokenized)

if ptypes.is_numeric_dtype(ser):

if ptypes.is_bool_dtype(ser):
return stype.categorical
# Candidates: numerical, categorical
if ptypes.is_float_dtype(ser) and not (has_nan and
(ser % 1 == 0).all()):
Expand Down
Loading