Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asccol
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Owen Graham
asccol
Commits
b693f4b2
Verified
Commit
b693f4b2
authored
2 years ago
by
Owen Graham
Browse files
Options
Downloads
Patches
Plain Diff
Remove `Columns` class; do the work in `DataSpec`
parent
1cc21a71
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-4
4 additions, 4 deletions
README.md
asccol.py
+2
-19
2 additions, 19 deletions
asccol.py
with
6 additions
and
23 deletions
README.md
+
4
−
4
View file @
b693f4b2
...
...
@@ -9,7 +9,7 @@ width.
```
py
import
math
import
sys
from
asccol
import
DataSpec
,
Columns
,
parse_data
import
asccol
def
simple_time
(
s
):
"""
Convert a HHMM string to an (H, M) tuple.
"""
...
...
@@ -24,9 +24,9 @@ def filtered_float(s):
# 10 minute data
# See https://amrc.ssec.wisc.edu/data/ftp/pub/aws/q10/q10readme.txt
Q10
=
DataSpec
(
Q10
=
asccol
.
DataSpec
(
leading
=
2
,
# lines to delete
cols
=
Columns
(
cols
=
(
(
'
year
'
,
int
,
4
),
# keyword, type (converter function), width
(
'
jdate
'
,
int
,
4
),
(
'
month
'
,
int
,
3
),
...
...
@@ -41,7 +41,7 @@ Q10 = DataSpec(
),
)
for
row
in
parse_data
(
sys
.
stdin
,
Q10
):
for
row
in
asccol
.
parse_data
(
sys
.
stdin
,
Q10
):
print
(
row
)
```
...
...
This diff is collapsed.
Click to expand it.
asccol.py
+
2
−
19
View file @
b693f4b2
...
...
@@ -6,31 +6,14 @@ Column = namedtuple('Column', ('name', 'type', 'width'))
class
DataSpec
:
"""
Details about how to parse an aligned data file.
Arguments:
cols (Columns): columns
'
name, type, and width
leading (int): number of leading lines to ignore
"""
"""
Details about how to parse an aligned data file.
"""
def
__init__
(
self
,
cols
,
leading
=
0
):
self
.
cols
=
cols
self
.
cols
=
tuple
(
map
(
Column
.
_make
,
cols
))
self
.
leading
=
leading
self
.
namedtuple
=
namedtuple
(
'
row
'
,
(
col
.
name
for
col
in
cols
))
class
Columns
(
tuple
):
"""
Details about how to parse aligned data.
"""
def
__new__
(
cls
,
*
data
):
columns
=
map
(
Column
.
_make
,
data
)
return
tuple
.
__new__
(
cls
,
columns
)
def
__repr__
(
self
):
contents
=
'
,
'
.
join
(
map
(
repr
,
self
))
return
f
'
{
type
(
self
).
__name__
}
(
{
contents
}
)
'
def
parse_data
(
stream
,
dataspec
):
"""
Read lines from `stream` and yield `namedtuple` data.
"""
for
line_num
,
line
in
enumerate
(
stream
,
start
=
1
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment