{"id":40702731,"url":"https://github.com/dssg/collate","last_synced_at":"2026-01-21T12:06:51.054Z","repository":{"id":46082114,"uuid":"71167444","full_name":"dssg/collate","owner":"dssg","description":"Aggregation SQL Query Builder","archived":false,"fork":false,"pushed_at":"2022-12-26T20:26:44.000Z","size":408,"stargazers_count":1,"open_issues_count":8,"forks_count":3,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-09-08T13:52:46.244Z","etag":null,"topics":["triage"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dssg.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-17T18:14:02.000Z","updated_at":"2019-09-09T00:32:18.000Z","dependencies_parsed_at":"2023-01-31T01:15:29.284Z","dependency_job_id":null,"html_url":"https://github.com/dssg/collate","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/dssg/collate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dssg%2Fcollate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dssg%2Fcollate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dssg%2Fcollate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dssg%2Fcollate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dssg","download_url":"https://codeload.github.com/dssg/collate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dssg%2Fcollate/sbom","scorecard":{"id":358019,"data":{"date":"2025-08-11","repo":{"name":"github.com/dssg/collate","commit":"30d051f21c2374bc802ecde4a557a6347dfc9940"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":5,"reason":"Found 10/19 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 25 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"18 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2019-124 / GHSA-38fc-9xqv-7f7q","Warn: Project is vulnerable to: PYSEC-2019-123 / GHSA-887w-45rq-vxgf","Warn: Project is vulnerable to: PYSEC-2022-238 / GHSA-h3qr-fjhm-jphw","Warn: Project is vulnerable to: GHSA-3ww4-gg4f-jr7f","Warn: Project is vulnerable to: GHSA-5cpq-8wj7-hf2v","Warn: Project is vulnerable to: GHSA-9v9h-cgj8-h64p","Warn: Project is vulnerable to: PYSEC-2018-52 / GHSA-fcf9-3qw3-gxmj","Warn: Project is vulnerable to: PYSEC-2021-62 / GHSA-hggm-jpg3-v476","Warn: Project is vulnerable to: GHSA-jm77-qphf-c4w8","Warn: Project is vulnerable to: GHSA-w7pp-m8wf-vj6r","Warn: Project is vulnerable to: GHSA-x4qr-2fvf-3mr5","Warn: Project is vulnerable to: PYSEC-2020-73","Warn: Project is vulnerable to: PYSEC-2021-437 / GHSA-5xp3-jfq3-5q8x","Warn: Project is vulnerable to: PYSEC-2020-173 / GHSA-gpvv-69j7-gwj8","Warn: Project is vulnerable to: PYSEC-2023-228 / GHSA-mq26-g339-26xf","Warn: Project is vulnerable to: PYSEC-2021-142 / GHSA-8q59-q68h-6hv4","Warn: Project is vulnerable to: PYSEC-2018-49 / GHSA-rprw-h62v-c2w7","Warn: Project is vulnerable to: PYSEC-2022-43017 / GHSA-qwmp-2cf2-g9g6"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T10:06:05.662Z","repository_id":46082114,"created_at":"2025-08-18T10:06:05.662Z","updated_at":"2025-08-18T10:06:05.662Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28632781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["triage"],"created_at":"2026-01-21T12:06:50.228Z","updated_at":"2026-01-21T12:06:51.047Z","avatar_url":"https://github.com/dssg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=======\ncollate\n=======\n\n\n.. image:: https://img.shields.io/pypi/v/collate.svg\n        :target: https://pypi.python.org/pypi/collate\n\n.. image:: https://travis-ci.org/dssg/collate.svg?branch=master\n        :target: https://travis-ci.org/dssg/collate\n\n.. image:: https://readthedocs.org/projects/collate/badge/?version=latest\n        :target: https://collate.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n.. image:: https://pyup.io/repos/github/dssg/collate/shield.svg\n     :target: https://pyup.io/repos/github/dssg/collate/\n     :alt: Updates\n\n.. image:: https://codecov.io/gh/dssg/collate/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/dssg/collate\n    :alt: Code Coverage\n\n\nAggregated feature generation made easy.\n\n* Free software for noncommercial use: `UChicago open source license \u003chttps://github.com/dssg/collate/blob/master/LICENSE\u003e`_.\n* Documentation: https://collate.readthedocs.io.\n\n**Note**: Collate is now a bundled component of `Triage \u003chttps://github.com/dssg/triage\u003e`_, and future development will take place there. To utilize collate within your custom pipeline, you may still import it from there.\n\n----\n\nOverview\n========\n\nCollate allows you to easily specify and execute statements like “find the number of restaurants in a given zip code that have had food safety violations within the past year.”  The real power is that it allows you to vary both the spatial and temporal windows, choosing not just zip code and one year, but a range over multiple partitions and times. Specifying features is also easier and more efficient than writing raw sql. Collate will automatically generate and execute all the required SQL scripts to aggregate the data across many groups in an efficient manner. We mainly use the results as features in machine learning models.\n\nInputs\n======\n\nTake for example `food inspections data from the City of Chicago \u003chttps://data.cityofchicago.org/Health-Human-Services/Food-Inspections/4ijn-s7e5\u003e`_. The table looks like this:\n\n\n============= =========== ===== =============== ========== =========== ===\ninspection_id license_no  zip   inspection_date results    violations  ...\n============= =========== ===== =============== ========== =========== ===\n1966765       80273       60636 2016-10-18      No Entry               ...\n1966314       2092894     60640 2016-10-11      Pass       …CORRECTED… ...\n1966286       2215628     60661 2016-10-11      Pass w/ C… …HAZARDOUS… ...\n1966220       2424039     60620 2016-10-07      Pass                   ...\n============= =========== ===== =============== ========== =========== ===\n\nThere are two spatial levels in the data: the specific restaurant (by its license number) and the zip code. And there is a date.\n\nAn example of an aggregate feature is the number of failed inspections. In raw SQL this could be calculated, for each restaurant, as so::\n\n    SELECT license_no, sum((results = 'Fail')::int) as failed_sum\n    FROM food_inspections GROUP BY license_no;\n\nIn collate, this aggregated column would be defined as::\n\n    Aggregate({\"failed\": \"(results = 'Fail')::int\"}, \"sum\", {'coltype':'aggregate', 'all': {'type': 'mean'}})\n\nNote that the SQL query is split into two parts: the first argument to ``Aggregate``\nis the computation to be performed and gives it a name (as a dictionary key), and\nthe second argument is the reduction function to perform. The third argument provides\na set of rules for how to handle imputation of null values in the resulting fields.\n\nSplitting the SQL like this makes it easy to generate lots of composable features \nas the outer product of these two lists.  For example, you may also be interested \nin the proportion of inspections that resulted in a failure in addition to the \ntotal number. This is easy to specify with the average value of the `failed` \ncomputation::\n\n    Aggregate({\"failed\": \"(results = 'Fail')::int\"}, [\"sum\",\"avg\"], {'coltype':'aggregate', 'all': {'type': 'mean'}})\n\n\nAggregations in collate easily aggregate this single feature across different spatiotemporal groups, e.g.::\n\n    Aggregate({\"failed\": \"(results = 'Fail')::int\"}, [\"sum\",\"avg\"], {'coltype':'aggregate', 'all': {'type': 'mean'}})\n    st = SpacetimeAggregation([fail],\n\t                           from_obj='food_inspections',\n                               groups=['license_no','zip'],\n                               intervals={\"license_no\":[\"2 year\", \"3 year\"], \"zip\": [\"1 year\"]},\n                               dates=[\"2016-01-01\", \"2015-01-01\"],\n                               date_column=\"inspection_date\",\n                               state_table='all_restaurants',\n                               state_group='license_no',\n                               schema='test_collate')\n\nThe ``SpacetimeAggregation`` object encapsulates the ``FROM`` section of the query\n(in this case it's simply the inspections table), as well as the ``GROUP BY``\ncolumns.  Not only will this create information about the individual restaurants\n(grouping by ``license_no``), it also creates \"neighborhood\" columns that add\ninformation about the region in which the restaurant is operating (by grouping by\n``zip``). The ``state_table`` specified here should contain the comprehensive set of\n``state_group`` entities and dates for which output should be generated for them,\nregardless if they exist in the ``from_obj``.\n\nEven more powerful is the sophisticated date range partitioning that the\n``SpacetimeAggregation`` object provides.  It will create multiple queries in\norder to create the summary statistics over the past 1, 2, or 3 years, looking\nback from either Jan 1, 2015 or Jan 1 2016. Executing this set of queries with::\n\n    st.execute(engine.connect()) # with a SQLAlchemy engine object\n\nwill create four new tables in the ``test_collate`` schema. The table\n``food_inspections_license_no`` will contain four feature columns for each\nlicense that describe the total number and proportion of failures over the past\ntwo or three years, with a date column that states whether it was looking\nbefore 2016 or 2015. Similarly, a ``food_inspections_zip`` table will have two\nfeature columns for every zip code in the database, looking at the total and\naverage number of failures in that neighborhood over the year prior to the date\nin the date column. The ``food_inspections_aggregation`` table joins these results \ntogether to make it easier to look at both neighborhood and restaurant-level \neffects for any given restaurant. Finally, the ``food_inspections_aggregation_imputed``\ntable fills in null values using the imputation rules specified in the ``Aggregate``\nconstructor.\n\nImputation Rules\n================\n\nImputation rules should be specified in the form of a dictionary::\n\n    {\n        'coltype': 'aggregate',\n        'all': {'type': 'mean'},\n        'max': {'type': 'constant', 'value': 137}\n    }\n\nThe ``coltype`` key of this dictionary must be one of ``aggregate``, ``categorical``, \nor ``array_categorical`` and informs how the imputation rules are applied.\n\nThe other keys of the dictionary are the reduction functions used by the aggregate\n(such as ``sum``, ``count``, ``avg``, etc.) or ``all`` as a catch-all. Function-specific\nrules will take precedence over the catch-all rule. The values associated with these\nkeys are each a dictionary with a required ``type`` key specifying the rule type and\nother rule-specific keys.\n\nCurrently available imputation rules:\n    * ``mean``: The average value of the feature (for ``SpacetimeAggregation`` the mean is taken within-date).\n    * ``constant``: Fill with a constant value from a required ``value`` parameter.\n    * ``zero``: Fill with zero.\n    * ``zero_noflag``: Fill with zero without generating an \"imputed\" flag. This option should be used only for cases where null values are explicitly known to be zero such as absence of an entity from an events table indicating that no such event has occurred.\n    * ``null_category``: Only available for categorical features. Just flag null values with the null category column.\n    * ``binary_mode``: Only available for aggregate column types. Takes the modal value for a binary feature.\n    * ``error``: Raise an exception if any null values are encountered for this feature.\n\nOutputs\n=======\n\nThe main output of a collate aggregation is a database table with all of the aggregated features joined to a list of entities.\n\n\nTODO: sample rows from the above aggregation.\n\n\nUsage Examples\n==============\n\nMultiple quantities\n~~~~~~~~~~~~~~~~~~~\nTODO\n\nMultiple functions\n~~~~~~~~~~~~~~~~~~\nTODO\n\nTuple quantity\n~~~~~~~~~~~~~~\nTODO\n\nDate substitution\n~~~~~~~~~~~~~~~~~\nTODO\n\nCategorical counts\n~~~~~~~~~~~~~~~~~~\nTODO\n\nNaming of features\n~~~~~~~~~~~~~~~~~~\nTODO\n\nMore complicated from_obj\n~~~~~~~~~~~~~~~~~~~~~~~~~\nTODO\n\nTechnical details\n=================\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdssg%2Fcollate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdssg%2Fcollate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdssg%2Fcollate/lists"}