fix: correct calculation error when series type is f32 #15
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.
Problem Cause
The Talib function expects input of type double. When the input Series has a data type of f32, it leads to abnormal calculation results. Initially, the
![image](https://private-user-images.githubusercontent.com/35556107/369604236-9d24f028-bbda-4261-abc1-df09c0d5fcb7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTc5MTAsIm5iZiI6MTczODk5NzYxMCwicGF0aCI6Ii8zNTU1NjEwNy8zNjk2MDQyMzYtOWQyNGYwMjgtYmJkYS00MjYxLWFiYzEtZGYwOWMwZDVmY2I3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA2NTMzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlkNTJlYWRlOGI5YzI1MWI5M2NlMjQwNzFkZjc0YjhkZTk0MjQxOWYyNTQ4NmQwNDJlMWYxNzIyNWJmNjU4ZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.yO1W1BqO-NrcVPEeNE-INwISHV42JW9H6bTSyQp9xX0)
to_float
function of Polars was used for type conversion, but this function does not handle the conversion from f32 to f64 since f32 is already a floating-point type. Passing the chunk pointer of type f32 directly as double to the Talib calculation results in memory alignment issues, affecting the calculation results. As encountered in issue #11, the attached image shows that fields likeadjusted_close
are of type f32.Changes Made
cast_series_to_f64
function toutils.rs
, which casts non-f64 types and rechunks.to_float
withcast_series_to_f64
inoverlap.rs
to convert non-f64 Series types, ensuring all input data for Talib functions are of type double.polars_ta_extension/src/overlap.rs
Line 21 in dcfd75a