Skip to content

Add fields missing from facets in observation response #694

Merged
kmoscoe merged 84 commits intodatacommonsorg:masterfrom
kmoscoe:api
Apr 6, 2026
Merged

Add fields missing from facets in observation response #694
kmoscoe merged 84 commits intodatacommonsorg:masterfrom
kmoscoe:api

Conversation

@kmoscoe
Copy link
Copy Markdown
Contributor

@kmoscoe kmoscoe commented Mar 31, 2026

This PR corrects an oversight that neglected to include 3 extra optional fields in the facet returned in the observation API response. It also changes one of the examples (in both REST and Python) to a different kind of statvar that shows units.

kmoscoe and others added 30 commits June 11, 2025 19:07
@kmoscoe kmoscoe requested review from miss-o-soup and n-h-diaz March 31, 2026 22:54
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Python and REST observation API documentation by adding scaling_factor, unit, and is_dc_aggregate fields to facet objects and transitioning examples to median household income data. The review feedback highlights multiple syntax errors in the updated examples, such as missing commas and brackets, and suggests using camelCase for the new fields to ensure consistency with existing API conventions.

Comment thread api/python/v2/observation.md Outdated
Comment on lines +72 to +73
"scaling_factor": "..."
"unit": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSON example is missing commas at the end of the lines, which makes the structure invalid. Additionally, please note that the preceding line (observationPeriod) also requires a comma to accommodate these new fields.

Suggested change
"scaling_factor": "..."
"unit": "..."
"scaling_factor": "...",
"unit": "..."

Comment thread api/python/v2/observation.md Outdated
"provenanceUrl": "...",
"measurementMethod": "...",
"observationPeriod": "..."
"scaling_factor": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new fields scaling_factor and is_dc_aggregate use snake_case, which is inconsistent with the existing camelCase fields in the same object (e.g., importName, measurementMethod, observationPeriod). Unless there is a specific requirement for snake_case in these new fields, it is recommended to use camelCase (scalingFactor, isDcAggregate) to maintain consistency across the API documentation and response structures.

Comment thread api/python/v2/observation.md Outdated
Comment on lines +125 to +126
"scaling_factor": "..."
"unit": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSON example is missing commas at the end of the lines. Also, ensure the preceding line (observationPeriod) has a trailing comma.

Suggested change
"scaling_factor": "..."
"unit": "..."
"scaling_factor": "...",
"unit": "..."

Comment thread api/python/v2/observation.md
Comment thread api/rest/v2/observation.md Outdated
Comment on lines +162 to +163
"scaling_factor": "..."
"unit": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing commas at the end of the lines in the JSON response signature. The preceding line (observationPeriod) also needs a comma.

Suggested change
"scaling_factor": "..."
"unit": "..."
"scaling_factor": "...",
"unit": "..."

Comment thread api/rest/v2/observation.md Outdated
Comment on lines +171 to +172
"scaling_factor": "..."
"unit": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing commas at the end of the lines in the JSON response signature.

Suggested change
"scaling_factor": "..."
"unit": "..."
"scaling_factor": "...",
"unit": "..."

Comment thread api/rest/v2/observation.md Outdated
Comment on lines +213 to +214
"scaling_factor": "..."
"unit": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing commas at the end of the lines in the JSON response signature.

Suggested change
"scaling_factor": "..."
"unit": "..."
"scaling_factor": "...",
"unit": "..."

Comment thread api/rest/v2/observation.md Outdated
Comment on lines +222 to +223
"scaling_factor": "..."
"unit": "..."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing commas at the end of the lines in the JSON response signature.

Suggested change
"scaling_factor": "..."
"unit": "..."
"scaling_factor": "...",
"unit": "..."

Copy link
Copy Markdown
Contributor

@n-h-diaz n-h-diaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

| observations | list of objects | Date and value pairs for the observations made in the time period |
| facets | object | Various properties of reported facets, where available, including the provenance of the data, etc. |
| facets | object | Various properties of reported facets, where available. |
| facets.importName | string | The name of the [provenance](/data_model.html#sources) or [dataset](/data_model.html#sources). |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this ever be the dataset name? (I think it's only provenance, but not sure of any counterexamples)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that it is technically the "provenance" name. However, in many (most?) the provenance and dataset are the same. Since "provenance" is often misunderstood, I used "dataset" as a more intuitive name. But if you think it's bad to make that shortcut, I can change it.

Comment thread api/rest/v2/observation.md Outdated
| facets.observationPeriod | string | The time period over which the observations were recorded, in [ISO 8601 duration format](https://docs.digi.com/resources/documentation/digidocs/90001488-13/reference/r_iso_8601_duration_format.htm). Not returned if unset. |
| facets.scaling_factor | integer | The denominator used in variables representing percentages or ratios. Not returned if unset. |
| facets.unit | string | The unit of measurement used. Not returned if unset. |
| facets.is_dc_aggregate | boolean | Set to true for variables that are auto-generated by Data Commons to aggregate data by place hierarchies. Not returned if false. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

place hierarchy is only one type of aggregation (for example we also aggregate multiple stat vars together or aggregate events into time series)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. Is there a typical time interval we use for these? Or does it vary, and it's encoded in the variable name? Can you give me an example of one? (I'll also include an example of a place-based one.)

"provenanceUrl": "...",
"measurementMethod": "...",
"observationPeriod": "..."
"importName": "<var>DATASET_NAME</var>",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see other comment) not sure if we're explicitly distinguishing between provenance and dataset

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, see my above comment. Provenance is such a confusing concept that I hate to use it. But if you think the inaccuracy is bad, I will fix it.

@kmoscoe kmoscoe merged commit e244b63 into datacommonsorg:master Apr 6, 2026
2 checks passed
@kmoscoe kmoscoe deleted the api branch April 14, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants