Skip to content

Commit

Permalink
ensure columns are strings before concatenation (#1857)
Browse files Browse the repository at this point in the history
Closes #1849

Ensures all columns are string columns prior to attempting string concatenation in `column_info.py`.

## By Submitting this PR I confirm:
- I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md).
- When the PR is ready for review, new or existing tests cover these changes.
- When the PR is ready for review, the documentation is up to date with these changes.

Authors:
  - Christopher Harris (https://github.com/cwharris)

Approvers:
  - Michael Demoret (https://github.com/mdemoret-nv)

URL: #1857
  • Loading branch information
cwharris authored Sep 6, 2024
1 parent 583149c commit 667b51f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/morpheus/morpheus/utils/column_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ def _process_column(self, df: pd.DataFrame) -> pd.Series:
The processed column as a string Series.
"""

first_col = df[self.input_columns[0]]
first_col = df[self.input_columns[0]].astype(str)

return first_col.str.cat(others=df[self.input_columns[1:]], sep=self.sep)
return first_col.str.cat(others=df[self.input_columns[1:]].astype(str), sep=self.sep)


@dataclasses.dataclass
Expand Down
7 changes: 5 additions & 2 deletions tests/test_column_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@ def test_string_cat_column():
],
sep=", ")

with pytest.raises(Exception):
string_cat_col_with_int._process_column(df)
actual = string_cat_col_with_int._process_column(df)

expected = pd.Series(["New York, 10001", "Dallas, 75001", "Austin, 73301"])

assert actual.equals(expected)


@pytest.mark.use_python
Expand Down

0 comments on commit 667b51f

Please sign in to comment.