CCRS
The Cannabis Compliance and Regulatory System (CCRS) is Washington State's traceability system for cannabis. The data is available to the public and can be wrangled with the following tools.
CCRS Methods
Method | Description |
---|---|
anonymize(df, columns=['CreatedBy', 'UpdatedBy']) |
Anonymizes a CCRS dataset by replacing the values in specified columns with hashes of the original values. |
find_detections(tests, analysis) |
Returns a list of keys for analytes detected for the specified analysis type and given tests. |
format_lab_results(df, results) |
Formats CCRS lab results data to be merged with another dataset. |
format_test_value(tests, compound) |
Filters given tests to contain only tests for a given compound . Then attempt to extract and return the value_key column as a numeric value from the first row of the filtered DataFrame. If this is not possible (e.g. if the DataFrame is empty), it returns None . |
get_datafiles(data_dir, dataset='inventory', desc=True) |
Returns a list of CCRS datafiles in a given directory, filtered by dataset type and sorted in either ascending or descending order. |
merge_datasets(df, datafiles, dataset='inventory) |
Merges a supplemental dataset with an existing dataset. |
save_dataset(data, data_dir, name='inventory) |
Saves a curated CCRS dataset to one or more files, with each file containing a maximum of 1 million rows. |
unzip_datafiles(data_dir) |
Unzips all files with the .zip file extension in the specified data_dir directory. |
CCRS Constants
Constant | Description |
---|---|
CCRS_DATASETS |
A dictionary of datasets that make up the CCRS. |
CCRS_ANALYSES |
A dictionary that maps analysis types to their corresponding standard analysis keys. |
CCRS_ANALYTES |
A dictionary that maps analytes to their corresponding standard keys. An analyte is a chemical or substance that is analyzed in a laboratory. Each key in the CCRS_ANALYTES dictionary is the name of an analyte as a string, and its value is a dictionary containing its key , analysis type , and units . |
Each key in the CCRS_DATASETS
dictionary represents a dataset and its value is a dictionary containing the following information:
dataset
: The name of the dataset as a string.singular
: The singular version of the dataset name as a string.fields
: A dictionary where the keys are the field names in the dataset and the values are their data types as strings.date_fields
: A list of field names in the dataset that are dates.
Each dataset in the CCRS_DATASETS
dictionary has a unique structure and set of fields, as depicted below: