Skip to content

Commit

Permalink
update ip conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cwharris committed Aug 28, 2024
1 parent b8500b2 commit c0afb2d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 44 deletions.
12 changes: 1 addition & 11 deletions python/morpheus/morpheus/_lib/src/messages/multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,7 @@ void MultiMessageInterfaceProxy::set_meta(MultiMessage& self, pybind11::object c
saved_index = py::none();
}

// Perform the update via slices
auto is_string_dtype = pybind11::module_::import("cudf.api.types").attr("is_string_dtype");
auto series = pybind11::module_::import("cudf").attr("Series");

if (is_string_dtype(series(value)).cast<bool>()) {
df[columns] = pybind11::str();
df[columns].attr("iloc")[row_indexer] = value;
} else {
df.attr("loc")[pybind11::make_tuple(df.attr("index")[row_indexer], columns)] = value;
}

df.attr("loc")[pybind11::make_tuple(df.attr("index")[row_indexer], columns)] = value;

// Reset the index if we changed it
if (!saved_index.is_none())
Expand Down
11 changes: 1 addition & 10 deletions python/morpheus/morpheus/messages/multi_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,7 @@ def set_meta(self, columns: typing.Union[None, str, typing.List[str]], value):

saved_index = df.index
df.reset_index(drop=True, inplace=True)

# TODO: when value is strings, make all values empty strings
from cudf.api.types import is_string_dtype

if is_string_dtype(cudf.Series(value)):
df[columns] = ""
df[columns].iloc[row_indexer] = value
else:
df.loc[df.index[row_indexer], columns] = value

df.loc[df.index[row_indexer], columns] = value
df.set_index(saved_index, inplace=True)
else:
# Need to determine the boolean mask to use indexes with df.loc
Expand Down
6 changes: 3 additions & 3 deletions python/morpheus/morpheus/parsers/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ip_to_int(values):
>>> ip.ip_to_int(cudf.Series(["192.168.0.1","10.0.0.1"]))
0 3232235521
1 167772161
dtype: int64
dtype: uint32
"""
return values.str.ip2int()

Expand All @@ -52,7 +52,7 @@ def int_to_ip(values):
Parameters
----------
values : cudf.Series
Integer representations of IP addresses
uint32 representations of IP addresses
Returns
-------
Expand All @@ -63,7 +63,7 @@ def int_to_ip(values):
--------
>>> import morpheus.parsers.ip as ip
>>> import cudf
>>> ip.int_to_ip(cudf.Series([3232235521, 167772161]))
>>> ip.int_to_ip(cudf.Series([3232235521, 167772161], dtype=cudf.api.types.dtype("uint32")))
0 192.168.0.1
1 10.0.0.1
dtype: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ def write_batch(x: MultiResponseMessage | ControlMessage):
out_df = cudf.DataFrame()

out_df["dt"] = (df["timestamp"] - time0).astype(np.int32)
out_df["src"] = df["src_ip"].str.ip_to_int().astype(np.int32)
out_df["dst"] = df["dest_ip"].str.ip_to_int().astype(np.int32)
out_df["src"] = df["src_ip"].str.ip_to_int().astype(np.uint32)
out_df["dst"] = df["dest_ip"].str.ip_to_int().astype(np.uint32)
out_df["lvl"] = df["secret_keys"].astype(np.int32)
out_df["data"] = df["data"]

Expand Down
18 changes: 0 additions & 18 deletions tests/test_multi_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,28 +266,10 @@ def test_set_meta_issue_286(filter_probs_df: cudf.DataFrame, use_series: bool):
if use_series:
values = cudf.Series(values)

import cupy

# hey = values[5:10].to_cupy()

mm1.set_meta('letters', values[0:5])
mm2.set_meta('letters', values[5:10])


# def test_something(filter_probs_df: cudf.DataFrame):

# values = list(string.ascii_letters)

# values =

# import cupy

# cupy.asarray(cudf.Series(list(string.ascii_letters)))

# # mm1.set_meta('letters', values[0:5])
# # mm2.set_meta('letters', values[5:10])


def _test_copy_ranges(df: typing.Union[cudf.DataFrame, pd.DataFrame]):
meta = MessageMeta(df)

Expand Down

0 comments on commit c0afb2d

Please sign in to comment.