{"id":20764181,"url":"https://github.com/zitsen/arrow-cast-guess-precision","last_synced_at":"2026-04-24T10:03:45.647Z","repository":{"id":209988729,"uuid":"725443952","full_name":"zitsen/arrow-cast-guess-precision","owner":"zitsen","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-18T09:59:21.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-25T22:30:56.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zitsen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-11-30T06:39:19.000Z","updated_at":"2024-01-10T21:47:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"5dd8772e-0c76-4059-8ae1-a90d875fef8b","html_url":"https://github.com/zitsen/arrow-cast-guess-precision","commit_stats":null,"previous_names":["zitsen/arrow-cast-guess-precision"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zitsen/arrow-cast-guess-precision","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitsen%2Farrow-cast-guess-precision","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitsen%2Farrow-cast-guess-precision/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitsen%2Farrow-cast-guess-precision/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitsen%2Farrow-cast-guess-precision/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zitsen","download_url":"https://codeload.github.com/zitsen/arrow-cast-guess-precision/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitsen%2Farrow-cast-guess-precision/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32218290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T09:47:08.147Z","status":"ssl_error","status_checked_at":"2026-04-24T09:46:41.165Z","response_time":64,"last_error":"SSL_read: 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":[],"created_at":"2024-11-17T10:49:05.692Z","updated_at":"2026-04-24T10:03:45.626Z","avatar_url":"https://github.com/zitsen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arrow-cast-guess-precision\n\nCast integer to timestamp with precision guessing options.\n\nJust replace [arrow::compute::cast] with [arrow_cast_guess_precision::cast] and everything done.\n\n```rust\nuse arrow::{\n    array::{Int64Array, TimestampNanosecondArray},\n    datatypes::{DataType, TimeUnit}\n};\n\nlet data = vec![1701325744956, 1701325744956];\nlet array = Int64Array::from(data);\nlet array = arrow_cast_guess_precision::cast(\n    \u0026array,\n    \u0026DataType::Timestamp(TimeUnit::Nanosecond, None),\n)\n.unwrap();\nlet nanos = array\n    .as_any()\n    .downcast_ref::\u003cTimestampNanosecondArray\u003e()\n    .unwrap();\nassert_eq!(nanos.value(0), 1701325744956 * 1000 * 1000);\n```\n\nThe difference to official [arrow::compute::cast] is that:\n\n- arrow v49 will cast integer directly to timestamp, but this crate(`arrow-cast-guess-precision = \"0.3.0\"`) will try to guess from the value.\n- arrow v48 does not support casting from integers to timestamp (`arrow-cast-guess-precision = \"0.2.0\"`).\n\nThe guessing method is:\n\n```rust\nuse arrow::datatypes::TimeUnit;\n\nconst GUESSING_BOUND_YEARS: i64 = 10000;\nconst LOWER_BOUND_MILLIS: i64 = 86400 * 365 * GUESSING_BOUND_YEARS;\nconst LOWER_BOUND_MICROS: i64 = 1000 * 86400 * 365 * GUESSING_BOUND_YEARS;\nconst LOWER_BOUND_NANOS: i64 = 1000 * 1000 * 86400 * 365 * GUESSING_BOUND_YEARS;\n\n#[inline]\nconst fn guess_precision(timestamp: i64) -\u003e TimeUnit {\n    let timestamp = timestamp.abs();\n    if timestamp \u003e LOWER_BOUND_NANOS {\n        return TimeUnit::Nanosecond;\n    }\n    if timestamp \u003e LOWER_BOUND_MICROS {\n        return TimeUnit::Microsecond;\n    }\n    if timestamp \u003e LOWER_BOUND_MILLIS {\n        return TimeUnit::Millisecond;\n    }\n    TimeUnit::Second\n}\n```\n\nUsers could set `ARROW_CAST_GUESSING_BOUND_YEARS` environment at build-time to control the guessing bound.\nhere is a sample list based on individual environment values:\n\n|    value | lower bound             |       Upper Bound       |\n| -------: | ----------------------- | :---------------------: |\n|      100 | 1970-02-06t12:00:00     |   2069-12-07T00:00:00   |\n|      200 | 1970-03-15t00:00:00     |   2169-11-13T00:00:00   |\n|      500 | 1970-07-02t12:00:00     |   2469-09-01T00:00:00   |\n| **1000** | **1971-01-01T00:00:00** | **2969-05-03T00:00:00** |\n|     2000 | 1972-01-01t00:00:00     |   3968-09-03T00:00:00   |\n|     5000 | 1974-12-31t00:00:00     |   6966-09-06T00:00:00   |\n|    10000 | 1979-12-30t00:00:00     |  +11963-05-13T00:00:00  |\n\nWe use `ARROW_CAST_GUESSING_BOUND_YEARS=1000` by default, just because `1000` milliseconds is `1` second so that the lower bound starts with `1971-01-01T00:00:00` which is one year after ZERO unix timestamp, and the upper bound is enough (even 100-years is enough though).\n\nLike [arrow::compute::cast], this crate also supports casting with specific options, checkout [CastOptions](arrow_cast_guess_precision::CastOptions).\n\n[arrow::compute::cast]: https://docs.rs/arrow/latest/arrow/compute/fn.cast.html\n[arrow_cast_guess_precision::cast]: https://docs.rs/arrow-cast-guess-precision/latest/arrow_cast_guess_precision/fn.cast.html\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitsen%2Farrow-cast-guess-precision","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzitsen%2Farrow-cast-guess-precision","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitsen%2Farrow-cast-guess-precision/lists"}