Skip to content
This repository was archived by the owner on Aug 3, 2021. It is now read-only.
This repository was archived by the owner on Aug 3, 2021. It is now read-only.

Default handling of empty strings #1

@MurrayData

Description

@MurrayData

I've been evaluating cuStrings/nvstrings in the latest Rapids container, and like it. It is very fast. I'm going to try it with some more involved string processing later.

I've tried it on UK Companies House corporate register, company names, and in this example the content of 10.8 million UK Tweets.

import nvstrings
filename = "/data/mesh_twitter_20181211/Data/mesh_twitter_20181211.csv"
%%time
a = nvstrings.from_csv(filename,3)

CPU times: user 1.69 s, sys: 1.82 s, total: 3.51 s
Wall time: 3.5 s

I've observed that an empty string in the source data is converted into a None type, and this causes errors in post analysis work for example summing records matching a criterion.

%%time
s = a.size()
c = a.count('\#')
h = c.count(0)
print("Number of tweets:",s,"Number of hashtags:",sum(c),"Tweets including a hashtag:",s-h,round(100.0*(s-h)/s,2),"%")

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<timed exec> in <module>

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

I am having to use a Python list comprehension, or a filter, to check for None type before further processing in such cases. Filter is ok for map reduction type operations, but if order or volume need to be preserved for concatenation, then it would need a list comprehension.

%%time
s = a.size()
c = [x if x is not None else 0 for x in a.count('\#')]
h = c.count(0)
print("Number of tweets:",s,"Number of hashtags:",sum(c),"Tweets including a hashtag:",s-h,round(100.0*(s-h)/s,2),"%")

Number of tweets: 10836607 Number of hashtags: 10801624 Tweets including a hashtag: 4641176 42.83 %
CPU times: user 833 ms, sys: 169 ms, total: 1 s
Wall time: 998 ms

In strings, an empty string can actually be a value ''. It may be concatenated with other fields too.

Therefore my suggestion, in the from_csv function, would be good to have an option to treat empty strings as a value or None. I would recommend '' as the default,. Possibly a Boolean argument?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions