|
19 | 19 | 'gocept-stream',
|
20 | 20 | 'fixedwidth',
|
21 | 21 | 'fixed',
|
22 |
| - 'djcopy' |
| 22 | + 'djcopy', |
| 23 | + 'ascii' |
23 | 24 | ],
|
24 | 25 | help='Which library to profile.')
|
25 | 26 |
|
@@ -149,6 +150,51 @@ def show_mem_profiler_results(mem):
|
149 | 150 | mem.disable()
|
150 | 151 |
|
151 | 152 |
|
| 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 | + |
152 | 198 | def run_fixed():
|
153 | 199 | """
|
154 | 200 | Load records with fixed.
|
@@ -482,7 +528,8 @@ def run_pandas_stream():
|
482 | 528 | 'pandas-stream': (run_pandas_stream, ),
|
483 | 529 | 'fixedwidth': (run_fixedwidth, ),
|
484 | 530 | 'fixed': (run_fixed, ),
|
485 |
| - 'djcopy': (run_djcopybook, ) |
| 531 | + 'djcopy': (run_djcopybook, ), |
| 532 | + 'ascii': (run_ascii, ) |
486 | 533 | }
|
487 | 534 |
|
488 | 535 |
|
|
0 commit comments