Skip to content

Conversation

Aniketsy
Copy link
Contributor

This PR updates logic selects the finest unit between the array and the offset, preventing rounding errors. A regression test is included to confirm correct behavior for affected offsets and units.

Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !

@Aniketsy Aniketsy marked this pull request as draft September 20, 2025 09:30

else:
result = type(self)._simple_new(res_values, dtype=res_values.dtype)
units = ["ns", "us", "ms", "s", "m", "h", "D"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are m, h, D possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm wrong I will update this .

idx_self = units.index(self.unit)
idx_offset = units.index(offset_unit)
res_unit = units[min(idx_self, idx_offset)]
dtype = tz_to_dtype(self.tz, unit=res_unit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont you need to cast res_values before calling simple_new?

Copy link
Contributor Author

@Aniketsy Aniketsy Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks! . Should we wrap this in try/except block?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suspect that The Right Way to do this would be to find the correct dtype before calling _from_sequence on L817 and pass it there

@Aniketsy Aniketsy marked this pull request as ready for review October 5, 2025 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: dt64[non_nano] + some_offsets incorrectly rounding

2 participants