def test_nbytes(): arr = AddrArray( [IPAddress('1.1.1.1'), IPAddress('2.2.2.2'), IPAddress('3.3.3.3')]) assert arr.nbytes == sum(sys.getsizeof(i) for i in arr)
def test_dtype(): arr = AddrArray( [IPAddress('1.1.1.1'), IPAddress('2.2.2.2'), IPAddress('3.3.3.3')]) # print(f'@@D !{type(arr.dtype)}!') # print(f'@@D !{arr.dtype}!') assert str(arr.dtype) == 'ipaddress'
def test_str_repr(): arr = AddrArray([IPAddress('1.1.1.1'), IPAddress('2.2.2.2')]) assert str(arr.dtype) == 'ipaddress' assert repr(arr.dtype) == "dtype('ipaddress')"
def test_len(): arr = AddrArray( [IPAddress('1.1.1.1'), IPAddress('2.2.2.2'), IPAddress('3.3.3.3')]) assert len(arr) == 3
def test_words(): df = pd.DataFrame({'ip':AddrArray(['1.1.1.1', '2.2.2.2'])}) s = df['ip'].ipaddr.words() actual = pd.Series([(1, 1, 1, 1), (2, 2, 2, 2)]) assert (s==actual).all()
def test_item(): arr = AddrArray([IPAddress('1.1.1.1'), IPAddress('2.2.2.2')]) assert arr.data[1] == IPAddress('2.2.2.2')
def test_iloc_value(): ip_str = '1.2.3.4' df = pd.DataFrame({'ip': AddrArray([ip_str, '2.2.2.2'])}) item = df.iloc[0]['ip'] assert item == IPAddress(ip_str)
def test_isna4(): arr = AddrArray([None, None, None, None]) assert (arr.isna() == np.array([True, True, True, True])).all()
def test_loc_value(): ip_str = '1.2.3.4' df = pd.DataFrame({'ip': AddrArray([ip_str])}) item = df.loc[0, 'ip'] assert item == IPAddress(ip_str)
def test_loc_seq(): ip_strs = ['1.2.3.4', '5.6.7.8', '9.10.11.12', '13.14.15.16'] df = pd.DataFrame({'ip': AddrArray(ip_strs)}) items = df.loc[[0, 2], 'ip'] assert (items == [IPAddress(ip) for ip in [ip_strs[0], ip_strs[2]]]).all()
def test_loc_type(): df = pd.DataFrame({'ip': AddrArray(['1.1.1.1', '2.2.2.2'])}) item = df.loc[0, 'ip'] assert type(item) == IPAddress
def test_bin(): df = pd.DataFrame({'ip':AddrArray(['1.1.1.1', '2.2.2.2'])}) s = df['ip'].ipaddr.bin() actual = ['0b1000000010000000100000001', '0b10000000100000001000000010'] assert (s==actual).all()
def test_words_6(): df = pd.DataFrame({'ip':AddrArray(['::1', '::2'])}) s = df['ip'].ipaddr.words() actual = pd.Series([(0, 0, 0, 0, 0, 0, 0, 1), (0, 0, 0, 0, 0, 0, 0, 2)]) assert (s==actual).all()
def test_isna2(): arr = AddrArray([None, IPAddress('2.2.2.2'), None]) assert (arr.isna() == np.array([True, False, True])).all()
def test_iloc_slice(): ip_strs = ['1.2.3.4', '5.6.7.8', '9.10.11.12', '13.14.15.16'] df = pd.DataFrame({'ip': AddrArray(ip_strs)}) item = df.iloc[1:2]['ip'] assert (item == [IPAddress(ip) for ip in ip_strs[1:2]]).all()
def test_isna3(): arr = AddrArray([IPAddress('1.1.1.1'), None, None]) assert (arr.isna() == np.array([False, True, True])).all()
def test_dtype(): df = pd.DataFrame({'ip': AddrArray(['1.1.1.1', '2.2.2.2'])}) assert str(df.ip.dtype) == 'ipaddress'
def test_eq(): ip1 = to_ipaddress(['1.1.1.1', '2.2.2.2']) ip2 = AddrArray([IPAddress('1.1.1.1'), IPAddress('2.2.2.2')]) assert (ip1 == ip2).all()
def test_hex(): df = pd.DataFrame({'ip':AddrArray(['1.1.1.1', '2.2.2.2'])}) s = df['ip'].ipaddr.hex() actual = ['0x1010101', '0x2020202'] assert (s==actual).all()