Skip to content

Commit 1dd6be8

Browse files
committed
Working on asciitables test.
1 parent 417d47a commit 1dd6be8

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

profile_melissa_zip_code.py

+49-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'gocept-stream',
2020
'fixedwidth',
2121
'fixed',
22-
'djcopy'
22+
'djcopy',
23+
'ascii'
2324
],
2425
help='Which library to profile.')
2526

@@ -149,6 +150,51 @@ def show_mem_profiler_results(mem):
149150
mem.disable()
150151

151152

153+
def run_ascii():
154+
"""
155+
Load records with asciitable.
156+
157+
* PyPy: OK. Development stopped (was moved into the Astropy project
158+
as astropy.io.ascii).
159+
* Source: https://github.com/taldcroft/asciitable
160+
* Docs: Good
161+
* Independent: NumPy not required but recommended.
162+
* Small: no
163+
* Can specify column data types: ?
164+
* Can read in chunks: no
165+
* Can skip columns: yes
166+
* Can stream: yes
167+
* Return type: wrapper around file or iterable
168+
* Memory usage: ?
169+
* Timing: ?
170+
"""
171+
import asciitable
172+
reader = asciitable.get_reader(
173+
Reader=asciitable.FixedWidth,
174+
header_start=None,
175+
data_start=2,
176+
names=(
177+
'zip_code', 'state_code', 'city_name', 'zip_type',
178+
'county_code', 'latitude', 'longitude', 'area_code',
179+
'finance_code', 'city_official', 'facility', 'msa_code',
180+
'pmsa_code', 'filler'
181+
),
182+
include_names=(
183+
'zip_code', 'state_code', 'city_name', 'county_code', 'area_code',
184+
'msa_code', 'pmsa_code'
185+
)
186+
)
187+
188+
data = reader.read('data/ZIP.DAT')
189+
190+
records = 0
191+
for row in data:
192+
records += 1
193+
print row
194+
if records == 100:
195+
break
196+
197+
152198
def run_fixed():
153199
"""
154200
Load records with fixed.
@@ -482,7 +528,8 @@ def run_pandas_stream():
482528
'pandas-stream': (run_pandas_stream, ),
483529
'fixedwidth': (run_fixedwidth, ),
484530
'fixed': (run_fixed, ),
485-
'djcopy': (run_djcopybook, )
531+
'djcopy': (run_djcopybook, ),
532+
'ascii': (run_ascii, )
486533
}
487534

488535

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'openpyxl==1.8.6',
2020
'pandas==0.16.0',
2121
'FixedWidth==0.99',
22-
'django-copybook==1.0.3'
22+
'django-copybook==1.0.3',
23+
'asciitable==0.8.0'
2324
]
2425
)

0 commit comments

Comments
 (0)