Package: rowgenerators
Row GeneratorsApplication UrlsApplication Urls provide structure and operations on URLS where the file the
URL refers to can’t, in general, simply be downloaded. For instance, you may
want to refer to a CSV file inside a ZIP archive, or a worksheet in an Excel
file. In conjunction withRow Generators, Application Urls are often
used to refer to tabular data stored on data repositories. For instance:Stored on the web:http://examples.com/file.csvInside a zip file on the web:http://example.com/archive.zip#file.csvA worksheet in an Excel file:http://example.com/excel.xls#worksheetA worksheet in an Excel file in a ZIP Archive:http://example.com/archive.zip#excel.xls;worksheetAn API:socrata+http://chhs.data.ca.gov/api/views/tthg-z4mfInstall$pipinstallappurlDocumentationSee the documentation athttp://row-generators.readthedocs.io/Development NotesRunning testsRunpython setup.py teststo run normal development tests. You can also runtox, which will
try to run the tests with python 3.4, 3.5 and 3.6, ignoring non-existent interpreters.Development Testing with DockerTesting during development for other versions of Python is a bit of a pain, since you have
to install the alternate version, and Tox will run all of the tests, not just the one you want.One way to deal with this is to install Docker locally, then run the docker test container
on the source directory. This is done automatically from the Makefile in appurl/tests$cd./docker$makebuild# to create the container image$makeshell# to run bash the containerYou now have a docker container where the /code directory is the appurl source dir.Now, run tox to build the tox virtual environments, then enter the specific version you want to
run tests for and activate the virtual environment.# tox
# cd .tox/py34
# source bin/activate # Activate the python 3.4 virtual env
# cd ../../
# python setup.py test # Cause test deps to get installed
#
# python -munittest appurl.test.test_basic.BasicTests.test_url_classes  # Run one testRow Data PipelineThe Rowpipe library manages row-oriented data transformers. Clients can create a RowProcessor() that has schema, composed of tables and columns, where each column cna have a “transform” that describes how to alter the data in the column.fromrowpipe.tableimportTablefromrowpipe.processorimportRowProcessordefdoubleit(v):returnint(v)*2env={'doubleit':doubleit}t=Table('foobar')t.add_column('id',datatype='int')t.add_column('other_id',datatype='int',transform='^row.a')t.add_column('i1',datatype='int',transform='^row.a;doubleit')t.add_column('f1',datatype='float',transform='^row.b;doubleit')t.add_column('i2',datatype='int',transform='^row.a')t.add_column('f2',datatype='float',transform='^row.b')In this table definition,other_idandi2columns are  initialized to the valu of theacolumn in the input row,
Thei1column is initialized to the input rowacolumn, then thedoubleitfunction is called on the value. In the last step, all of the values are cast to the types specified in thedatatypecolumn.The RowProcessor is then run using this table definition, and an input generator:classSource(object):headers='a b'.split()def__iter__(self):foriinrange(N):yieldi,2*irp=RowProcessor(Source(),t,env=env)Then,rpis a generator that returnsRowProxyobjects, which can be indexed as integers or by clolumn number:forrowinrp:v1=row['f1']v2=row[3]The RowProcessor creates Python code files and executes them.Transforms can have several steps, seperated by ‘;’. The first, prefixes with a ‘^’, initializes the value for the rest of the transforms. A transform that is prefixes with a ‘!’ is executed on exceptions.  Transform functions can have a variable signature; the tranform processor matches argument names. Valid argument names are:row. A rowProxy object for the input row. Allows access to any input row valuerow_n. Row number.scratch. A dict for temporary storageerrors. A defaultdict(set) for storing error reports for columns. Keys are column namesaccumulator. A dict for accumulating value, such as sums.pipe. Unusedbundle. Unusedsource. Reference to the input generator that is generating rowsv . The input row valueheader_s. The header for the column in the input row.i_s. The index of the column in the input rowheader_d. The header for the column in the output row.i_d.  The index of the column in the output row… and there is a whole lot more. This documentation is woefully incomplete …NotesThis repo still contains old code for Row Pipelines, which are in thepipeline.pyfile. These components can be combined to performd defined operations on rows, such as skipping rows based on a predicate, altering the number of rows, returning on ly the head or tail, etc. The code is not currently used ot tested.