Title: No support for null UnixTimestamp · Issue #2803 · feast-dev/feast · GitHub
Open Graph Title: No support for null UnixTimestamp · Issue #2803 · feast-dev/feast
X Title: No support for null UnixTimestamp · Issue #2803 · feast-dev/feast
Description: Expected Behavior This script should return online features, with one null in last_purchased_date from feast import Entity, FeatureView from feast.infra.offline_stores.file_source import FileSource from feast.repo_config import RegistryC...
Open Graph Description: Expected Behavior This script should return online features, with one null in last_purchased_date from feast import Entity, FeatureView from feast.infra.offline_stores.file_source import FileSource...
X Description: Expected Behavior This script should return online features, with one null in last_purchased_date from feast import Entity, FeatureView from feast.infra.offline_stores.file_source import FileSource...
Opengraph URL: https://github.com/feast-dev/feast/issues/2803
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"No support for null UnixTimestamp","articleBody":"## Expected Behavior \r\n\r\nThis script should return online features, with one null in `last_purchased_date`\r\n```python\r\nfrom feast import Entity, FeatureView\r\nfrom feast.infra.offline_stores.file_source import FileSource\r\nfrom feast.repo_config import RegistryConfig, RepoConfig\r\nfrom feast import FeatureStore\r\nfrom datetime import datetime\r\nfrom feast.types import Int32, UnixTimestamp\r\nfrom feast import Field\r\n\r\nimport pandas as pd\r\n\r\n\r\n# create dataset\r\npd.DataFrame([\r\n {\"user_id\": 1, \"event_timestamp\": datetime(2022, 5, 1), \"created\": datetime(2022, 5, 1), \"purchases\": 3, \"last_purchase_date\": datetime(2022, 4, 23, 13, 4, 1)},\r\n {\"user_id\": 2, \"event_timestamp\": datetime(2022, 5, 2), \"created\": datetime(2022, 5, 2), \"purchases\": 1, \"last_purchase_date\": datetime(2022, 2, 1, 11, 4, 1)},\r\n {\"user_id\": 3, \"event_timestamp\": datetime(2022, 5, 2), \"created\": datetime(2022, 5, 2), \"purchases\": 0, \"last_purchase_date\": None}, \r\n]).to_parquet('user_stats.parquet')\r\n\r\n\r\nuser = Entity(name=\"user_id\", description=\"user id\")\r\n\r\nuser_stats_view = FeatureView(\r\n name=\"user_stats\",\r\n entities=[user],\r\n source=FileSource(\r\n path=\"user_stats.parquet\",\r\n timestamp_field=\"event_timestamp\",\r\n created_timestamp_column=\"created\",\r\n ),\r\n schema=[\r\n Field(name=\"purchases\", dtype=Int32),\r\n Field(name=\"last_purchase_date\", dtype=UnixTimestamp),\r\n ]\r\n)\r\n\r\nonline_store_path = 'online_store.db'\r\nregistry_path = 'registry.db'\r\n\r\nrepo = RepoConfig(\r\n registry=\"registry.db\",\r\n project='feature_store',\r\n provider=\"local\",\r\n offline_store=\"file\",\r\n use_ssl=True, \r\n is_secure=True,\r\n validate=True,\r\n)\r\n\r\nfs = FeatureStore(config=repo)\r\n\r\nfs.apply([user, user_stats_view])\r\n\r\nfs.materialize_incremental(end_date=datetime.utcnow())\r\n\r\n\r\nentity_rows = [{\"user_id\": i} for i in range(1, 4)]\r\n\r\n\r\nfeature_df = fs.get_online_features(\r\n features=[\r\n \"user_stats:purchases\",\r\n \"user_stats:last_purchase_date\",\r\n ],\r\n entity_rows=entity_rows\r\n).to_df()\r\nprint(feature_df)\r\n```\r\n\r\n## Current Behavior\r\n\r\n```\r\nMaterializing 1 feature views to 2022-06-16 20:30:41-06:00 into the sqlite online store.\r\n\r\nSince the ttl is 0 for feature view user_stats, the start date will be set to 1 year before the current time.\r\nuser_stats from 2021-06-17 20:30:41-06:00 to 2022-06-16 20:30:41-06:00:\r\n100%|████████████████████████████████████████████████████████████████| 3/3 [00:00\u003c00:00, 420.36it/s]\r\nTraceback (most recent call last):\r\n File \"null_timestamp_example.py\", line 59, in \u003cmodule\u003e\r\n feature_df = fs.get_online_features(\r\n File \"/Users/apope/feast/sdk/python/feast/online_response.py\", line 79, in to_df\r\n return pd.DataFrame(self.to_dict(include_event_timestamps))\r\n File \"/Users/apope/feast/sdk/python/feast/online_response.py\", line 59, in to_dict\r\n response[feature_ref] = [\r\n File \"/Users/apope/feast/sdk/python/feast/online_response.py\", line 60, in \u003clistcomp\u003e\r\n feast_value_type_to_python_type(v) for v in feature_vector.values\r\n File \"/Users/apope/feast/sdk/python/feast/type_map.py\", line 74, in feast_value_type_to_python_type\r\n val = datetime.fromtimestamp(val, tz=timezone.utc)\r\nOSError: [Errno 84] Value too large to be stored in data type\r\n```\r\n\r\n## Steps to reproduce\r\n\r\n### Specifications\r\n\r\n- Version: 0.21.2\r\n- Platform: Mac\r\n- Subsystem: \r\n\r\n## Possible Solution\r\n\r\nThis happens because, while materializing, in `_python_datetime_to_int_timestamp()` the `NaT` value gets converted to `-9223372036854775808`\r\n\r\n```python\r\nIn [108]:\r\nfrom typing import cast, Sequence\r\nimport numpy as np\r\n\r\ncast(Sequence[np.int_], np.array(['nat'], dtype='datetime64[ns]').astype('datetime64[s]').astype(np.int_))\r\nOut [108]:\r\narray([-9223372036854775808])\r\n```\r\n\r\nWhich is out of range for `datetime.fromtimestamp()`:\r\n```python\r\nIn [109]:\r\nfrom datetime import datetime, timezone\r\n\r\ndatetime.fromtimestamp(-9223372036854775808, tz=timezone.utc)\r\n\r\nTruncated Traceback (Use C-c C-$ to view full TB):\r\n/tmp/ipykernel_58/1143168205.py in \u003cmodule\u003e\r\n 1 from datetime import datetime, timezone\r\n 2 \r\n----\u003e 3 val = datetime.fromtimestamp(-9223372036854775808, tz=timezone.utc)\r\n\r\nOSError: [Errno 75] Value too large for defined data type\r\n```\r\n\r\nA simple fix would be to leave the materialization logic as-is and, when deserializing in `feast_value_type_to_python_type()`, just catch this one value and return a null instead.","author":{"url":"https://github.com/aapope","@type":"Person","name":"aapope"},"datePublished":"2022-06-16T21:14:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2803/feast/issues/2803"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d6f19343-92bd-1535-14d9-bce452296b55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8ECE:3A860B:54BDED:7801AB:6978B825 |
| html-safe-nonce | 2ac376b2668d93aa724b7b4e0c2ded5601f6011fb0735f5744177a7b5b676be4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RUNFOjNBODYwQjo1NEJERUQ6NzgwMUFCOjY5NzhCODI1IiwidmlzaXRvcl9pZCI6IjIzOTI5ODc0MDc3OTI3ODEzNDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d8e71225c9c7170a57f74bc94b989733892901de5cab1e99f65638b19df76425 |
| hovercard-subject-tag | issue:1274088444 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/feast-dev/feast/2803/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc478a25baf9b9b34693e873e92094354db0cd046af972c451215a3dfa100ced/feast-dev/feast/issues/2803 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc478a25baf9b9b34693e873e92094354db0cd046af972c451215a3dfa100ced/feast-dev/feast/issues/2803 |
| og:image:alt | Expected Behavior This script should return online features, with one null in last_purchased_date from feast import Entity, FeatureView from feast.infra.offline_stores.file_source import FileSource... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aapope |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8fe1bd499c6d7cea4c6a731e1024678b67678c64baac66af24f17b565ee0651e |
| turbo-cache-control | no-preview |
| go-import | github.com/feast-dev/feast git https://github.com/feast-dev/feast.git |
| octolytics-dimension-user_id | 57027613 |
| octolytics-dimension-user_login | feast-dev |
| octolytics-dimension-repository_id | 161133770 |
| octolytics-dimension-repository_nwo | feast-dev/feast |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 161133770 |
| octolytics-dimension-repository_network_root_nwo | feast-dev/feast |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 54838e42b488f7a96e473ea27343ed90b6d97959 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width