{"id":5560,"library":"adjust-precision-for-schema","title":"Adjust Precision for Schema","description":"This library (version 0.3.4) is designed for use in Singer.io data integration targets to address and overcome precision differences that can arise between various data source systems, Python's native numeric types, and target data warehouses or databases. It aims to ensure data consistency and accuracy, particularly for decimal and floating-point numbers, during the ETL process. The release cadence appears to be irregular, based on available PyPI data.","status":"active","version":"0.3.4","language":"en","source_language":"en","source_url":null,"tags":["data processing","singer-io","etl","schema","precision","decimal","data quality"],"install":[{"cmd":"pip install adjust-precision-for-schema","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"This is a hypothesized main function based on common Python package naming conventions and the library's purpose. The actual function name may vary.","symbol":"adjust_precision","correct":"from adjust_precision_for_schema import adjust_precision"}],"quickstart":{"code":"import json\nfrom adjust_precision_for_schema import adjust_precision\n\n# Example Singer SCHEMA message (simplified)\n# This schema defines a 'price' field with a logical 'decimal' type\n# and an implied precision/scale (e.g., up to 2 decimal places).\nschema_message = {\n    \"type\": \"SCHEMA\",\n    \"stream\": \"products\",\n    \"schema\": {\n        \"type\": \"object\",\n        \"properties\": {\n            \"id\": {\"type\": \"integer\"},\n            \"name\": {\"type\": \"string\"},\n            \"price\": {\n                \"type\": [\"number\", \"null\"],\n                \"\"_singer_type\": \"decimal\",\n                \"\"maximum\": 1000000000000000000000000000000000000.00,\n                \"\"multipleOf\": 0.01\n            }\n        }\n    },\n    \"key_properties\": [\"id\"]\n}\n\n# Example Singer RECORD message\nrecord_message = {\n    \"type\": \"RECORD\",\n    \"stream\": \"products\",\n    \"record\": {\n        \"id\": 1,\n        \"name\": \"Product A\",\n        \"price\": 123.456789  # Value with more precision than schema intends\n    }\n}\n\n# Another record with a value that should be adjusted minimally\nrecord_message_2 = {\n    \"type\": \"RECORD\",\n    \"stream\": \"products\",\n    \"record\": {\n        \"id\": 2,\n        \"name\": \"Product B\",\n        \"price\": 99.99999999999999 # Value that should round up\n    }\n}\n\n# Hypothetical function call to adjust precision based on the schema\n# The exact API (e.g., arguments, return type) is inferred.\nadjusted_record_1 = adjust_precision(record_message['record'], schema_message['schema'])\nadjusted_record_2 = adjust_precision(record_message_2['record'], schema_message['schema'])\n\nprint(\"Original Record 1 Price:\", record_message['record']['price'])\nprint(\"Adjusted Record 1 Price:\", adjusted_record_1['price'])\n\nprint(\"Original Record 2 Price:\", record_message_2['record']['price'])\nprint(\"Adjusted Record 2 Price:\", adjusted_record_2['price'])","lang":"python","description":"This example demonstrates how the `adjust_precision` function (hypothesized based on the library's purpose) might be used within a Singer.io data pipeline. It takes a data record and a JSON Schema, adjusting numeric values within the record to conform to the precision and scale implied by the schema, particularly for fields marked with `\"_singer_type\": \"decimal\"` and `\"multipleOf\"`."},"warnings":[{"fix":"Explicitly define `multipleOf` (e.g., `0.01` for two decimal places) for `number` types in your JSON Schema that represent decimals, or leverage Singer-specific extensions for `precision` and `scale` if the target supports them.","message":"Without an explicit `multipleOf` or `precision`/`scale` definition in your Singer.io JSON Schema, the library may not be able to correctly infer the desired precision for numeric fields. Ensure your schemas are as explicit as possible for critical numeric types.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use Python's `decimal` module for internal representation and calculations when absolute precision is critical, and ensure the library's internal logic aligns with the target system's rounding rules (e.g., HALF_UP, HALF_EVEN).","message":"Floating-point inaccuracies in Python can lead to unexpected rounding behavior. While this library aims to mitigate this, always test the precision adjustments with edge cases (e.g., `X.Y4999` vs `X.Y5000`) to ensure desired rounding.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement robust schema validation and data quality checks in your Singer.io pipeline. Monitor data for unexpected precision changes at both the source and after adjustment. Consider versioning your schemas and communicating changes to consumers.","message":"Schema evolution and changes in source data precision can silently break downstream data pipelines if not properly managed. Relying solely on automatic precision adjustment without validation can mask underlying data quality issues.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}