ContinuumIO / cyberpandas

IP Address dtype and block for pandas
BSD 3-Clause "New" or "Revised" License
104 stars 23 forks source link

Issue filtering by ip address #46

Open rmbittmann opened 3 years ago

rmbittmann commented 3 years ago

Hi,

I might have missed something as I am not that experienced. When I use cyberpandas to convert to IP address, I cannot filter the data frame based on the IP. Here is an example.

import cyberpandas as cpd import ipaddress as ip import numpy as np import pandas as pd

df = pd.DataFrame(np.array(([ip.IPv4Address('1.1.1.1'), 1], [ip.IPv4Address('2.2.2.2'), 2], [ip.IPv4Address('3.3.3.3'), 3])), columns=['ip', 'payload']) df

df['ip'][0] == ip.IPv4Address('1.1.1.1')

df[df['ip'] == ip.IPv4Address('1.1.1.1')]

Works well.

However df2 = pd.DataFrame(np.array((['1.1.1.1', 1], ['2.2.2.2', 2], ['3.3.3.3', 3])), columns=['ip', 'payload']) df2['ip'] = cpd.to_ipaddress(df2['ip']) df2

df2['ip'][0] == ip.IPv4Address('1.1.1.1')

df2[df2['ip'] == ip.IPv4Address('1.1.1.1')]

In the last command it does not find the correct row as expected as in the previous example, and returns an empty data frame.

What did I miss? What should be done for it to work?

I am using python 3.9.1. with the latest updated packages.

Thanks, Rani