-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazyMerger.py
More file actions
36 lines (25 loc) · 835 Bytes
/
Copy pathlazyMerger.py
File metadata and controls
36 lines (25 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import time
import numpy
import string
import dask.bag as db
unwanted_lines = [x for x in string.whitespace]
unwanted_lines.append('')
def lazyMerger(wordlists, name):
start = time.perf_counter()
blocksize = max([os.path.getsize(x) for x in wordlists]) // 16
bag = db.read_text(wordlists, blocksize=blocksize, encoding='latin-1')
df = bag.to_dataframe(meta={'p': str})
if df.p.isin(unwanted_lines).any().compute():
df = df.replace(unwanted_lines, numpy.nan).dropna()
df = df.drop_duplicates().compute()
with open(name, 'w') as out:
out.write(
df.to_string(
header=False,
index=False).replace(
' ',
'').replace(
'\\n',
''))
return time.perf_counter() - start