Fix unit processing in timestamps#81
Open
jubeira wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There's an inconsistency in the scripts that download and parse the pricing data:
Diagnosis
The error isn't caused by the downloaded data — it's caused by a pandas 3.x behavior change in how DatetimeIndex/Series are converted to int64.
Root cause
In quantammsim/utils/data_processing/amalgamated_data_utils.py:36-46 (forward_fill_ohlcv_data):
In pandas ≤2.x, pd.date_range(...) always produced
datetime64[ns], soastype(np.int64) // 10**6correctly converted ns → ms. In pandas 3.0,pd.to_datetime(..., unit="ms")producesdatetime64[ms], andpd.date_rangepropagates thatresolution. Now
astype(np.int64)already returns ms — dividing by 10**6 again yields tiny garbage values.Example:
1502942 ms reinterpreted as ms is 1970-01-01 00:25:02.942000 — exactly the value in the error. The forward_fill_ohlcv_data reindex then gives every row the same garbage timestamp, so the very first diff fails the equality check.
Why now?
Two contributing things landed at once:
to handle this OK (16 digits → //10⁶ → *1000).
Proposed fix
Force the unit explicitly before converting to int64. The pattern stops depending on whatever resolution pandas chose.