Skip to content

Conversation

@HyukjinKwon
Copy link
Member

@HyukjinKwon HyukjinKwon commented Dec 26, 2025

Rationale for this change

The test test_sequence_timestamp_from_int_with_unit() was marked with
@pytest.mark.pandas, meaning it was skipped when pandas was not installed.
This left the non-pandas code path untested.

Specifically in order to test:

if _pandas_api.have_pandas:
return _pandas_api.pd.Timestamp(value, tz=tzinfo, unit='ns')
# otherwise safely truncate to microsecond resolution datetime
if value % 1000 != 0:
raise ValueError(
f"Nanosecond resolution temporal type {value} is not safely "
"convertible to microseconds to convert to datetime.datetime. "
"Install pandas to return as Timestamp with nanosecond "
"support or access the .value attribute."
)

The TODO was introduced in commit 286bf7c when making pandas
an optional dependency:

# TODO(wesm): This test might be rewritten to assert the actual behavior
# when pandas is not installed

What changes are included in this PR?

Split nanosecond timestamp testing into separate tests to cover both pandas and non-pandas code paths:

  1. Kept test_sequence_timestamp_from_int_with_unit() unchanged (tests s/ms/us units without pandas requirement)
  2. Removed TODO comment and created three new nanosecond-specific tests:
    • test_sequence_timestamp_from_int_with_unit_nanosecond (@pytest.mark.pandas): Tests pd.Timestamp with full nanosecond precision
    • test_sequence_timestamp_from_int_nanosecond_without_pandas (@pytest.mark.nopandas): Tests that values not divisible by 1000 raise ValueError
    • test_sequence_timestamp_from_int_nanosecond_divisible_without_pandas (@pytest.mark.nopandas): Tests successful conversion when values are divisible by 1000

Are these changes tested?

Yes. I manually tested with/without pandas:

conda remove pandas
pytest pyarrow/tests/test_convert_builtin.py -k "timestamp_from_int_with_unit" -xvs
conda install pandas==2.3.3
pytest pyarrow/tests/test_convert_builtin.py -k "timestamp_from_int_with_unit" -xvs

Are there any user-facing changes?

No, test-only.

@github-actions
Copy link

⚠️ GitHub issue #48654 has been automatically assigned in GitHub to PR creator.

Copy link
Member

@AlenkaF AlenkaF left a comment

Choose a reason for hiding this comment

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

Happy New Year! =)

Thank you for another contribution ❤️ The change looks good to me. The existing test is kept as is with only the nanosecond case excluded and turned into two separate (pandas and nopandas) tests in order to check the code path when pandas is not installed.

One question I have is: I think the case where pandas is not installed and nanosecond int value can be divided by 1000 is not included in the tests? Can we add that?

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jan 5, 2026
@HyukjinKwon
Copy link
Member Author

Thank you ! let me take a look!

@HyukjinKwon
Copy link
Member Author

Updated the PR description as well 👍

Copy link
Member

@AlenkaF AlenkaF left a comment

Choose a reason for hiding this comment

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

Thanks!

@AlenkaF AlenkaF merged commit 7ba1a7b into apache:main Jan 6, 2026
15 checks passed
@AlenkaF AlenkaF removed the awaiting committer review Awaiting committer review label Jan 6, 2026
@HyukjinKwon
Copy link
Member Author

yay!

@conbench-apache-arrow
Copy link

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 7ba1a7b.

There weren't enough matching historic benchmark results to make a call on whether there were regressions.

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants