You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "aboss123 (via GitHub)" <gi...@apache.org> on 2023/07/25 20:23:48 UTC
[GitHub] [arrow] aboss123 opened a new pull request, #36877: MINOR: [Python] Fix Timestamp scalar repr error on values outside datetime range
aboss123 opened a new pull request, #36877:
URL: https://github.com/apache/arrow/pull/36877
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
https://github.com/apache/arrow/issues/36323
### What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Changed the way repr is handled for TimestampScalar
### Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
I have added a very basic test for this change to see whether it will error or not if outside the range.
### Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
The functionality of TimestampScalar's repr now uses the `strftime` function.
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] aboss123 commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "aboss123 (via GitHub)" <gi...@apache.org>.
aboss123 commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1651934403
> There seems to be some linting issues and the following test is failing:
>
> ```
> __________________ test_sequence_timestamp_from_int_with_unit __________________
>
> @pytest.mark.pandas
> def test_sequence_timestamp_from_int_with_unit():
> # TODO(wesm): This test might be rewritten to assert the actual behavior
> # when pandas is not installed
>
> data = [1]
>
> s = pa.timestamp('s')
> ms = pa.timestamp('ms')
> us = pa.timestamp('us')
> ns = pa.timestamp('ns')
>
> arr_s = pa.array(data, type=s)
> assert len(arr_s) == 1
> assert arr_s.type == s
> > assert repr(arr_s[0]) == (
> "<pyarrow.TimestampScalar: datetime.datetime(1970, 1, 1, 0, 0, 1)>"
> )
> E assert "<pyarrow.Tim...01T00:00:01'>" == '<pyarrow.Tim... 1, 0, 0, 1)>'
> E - <pyarrow.TimestampScalar: datetime.datetime(1970, 1, 1, 0, 0, 1)>
> E + <pyarrow.TimestampScalar: '1970-01-01T00:00:01'>
> ```
Regarding this error I have a question. The docs appear to want the repr of the TimestampScalar to show datetime but perhaps it could display in a different format? As the initial issue mentions, values that are put in outside the range of the datetime values could break the repr functionality so would it be wise to change docs to show `strftime` output versus the datetime one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] danepitkin commented on a diff in pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "danepitkin (via GitHub)" <gi...@apache.org>.
danepitkin commented on code in PR #36877:
URL: https://github.com/apache/arrow/pull/36877#discussion_r1276676467
##########
python/pyarrow/scalar.pxi:
##########
@@ -113,8 +113,12 @@ cdef class Scalar(_Weakrefable):
else:
with nogil:
check_status(self.wrapped.get().Validate())
-
+
def __repr__(self):
+ if isinstance(self, TimestampScalar):
Review Comment:
Good catch! Yes, let's include the timezone when supplied. Let's try and follow the ISO 8601 standard https://en.wikipedia.org/wiki/ISO_8601 and use `%z`. Maybe something like `%Y-%m-%dT%H:%M:%S%z` e.g.
```
>>> res = pa.scalar("2000-01-01").cast(pa.timestamp("s"))
>>> res_with_tz = pc.assume_timezone(res, "America/New_York")
>>> str(pc.strftime(res_with_tz, format='%Y-%m-%dT%H:%M:%S%z'))
'2000-01-01T00:00:00-0500'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] aboss123 commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "aboss123 (via GitHub)" <gi...@apache.org>.
aboss123 commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1656300195
Given the comments I've made some changes. Please let me know if there is anything else needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657363456
```
Only contributors can submit requests to this bot. Please ask someone from the community for help with getting the first commit in.
The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/5709570640
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] danepitkin commented on a diff in pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "danepitkin (via GitHub)" <gi...@apache.org>.
danepitkin commented on code in PR #36877:
URL: https://github.com/apache/arrow/pull/36877#discussion_r1275248700
##########
python/pyarrow/scalar.pxi:
##########
@@ -113,8 +113,12 @@ cdef class Scalar(_Weakrefable):
else:
with nogil:
check_status(self.wrapped.get().Validate())
-
+
def __repr__(self):
+ if isinstance(self, TimestampScalar):
Review Comment:
Instead of checking for TimestampScalar type in the base class, let's override `__repr__` in the `cdef class TimestampScalar`.
Here is the implementation of `Array.__repr__`, which is mentioned in the issue linked. https://github.com/apache/arrow/blob/main/python/pyarrow/array.pxi#L1222
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657261356
```
Command '['git', '-C', '/tmp/tmpryb2in98/arrow', 'fetch', 'origin', 'pull/36877/head:main']' returned non-zero exit status 128.
The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/5708248418
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] aboss123 commented on a diff in pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "aboss123 (via GitHub)" <gi...@apache.org>.
aboss123 commented on code in PR #36877:
URL: https://github.com/apache/arrow/pull/36877#discussion_r1275331810
##########
python/pyarrow/scalar.pxi:
##########
@@ -113,8 +113,12 @@ cdef class Scalar(_Weakrefable):
else:
with nogil:
check_status(self.wrapped.get().Validate())
-
+
def __repr__(self):
+ if isinstance(self, TimestampScalar):
Review Comment:
Got it! I can make that change. How would you specify the time format exactly. It mentions the default [here](https://arrow.apache.org/docs/python/generated/pyarrow.compute.strftime.html) but the tests specify `<pyarrow.TimestampScalar: datetime.datetime(2012, 1, 1, 0, 0, tzinfo=<UTC>)>`. This has timezone info would you like the format to include `%z` & `%Z` modifiers to view this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] aboss123 commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "aboss123 (via GitHub)" <gi...@apache.org>.
aboss123 commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657363016
@github-actions crossbow submit python
> ```
> Command '['git', '-C', '/tmp/tmpryb2in98/arrow', 'fetch', 'origin', 'pull/36877/head:main']' returned non-zero exit status 128.
> The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/5708248418
> ```
Is there something that needs to be changed considering this did not exit properly?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657261214
@github-actions crossbow submit -g python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657373376
Ah, could you re-submit this PR from a feature branch instead of `main`?
Our CI tool (Crossbow doesn't support `main` branch on fork.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] aboss123 commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "aboss123 (via GitHub)" <gi...@apache.org>.
aboss123 commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657393334
> Ah, could you re-submit this PR from a feature branch instead of `main`? Our CI tool (Crossbow doesn't support `main` branch on fork.)
I have created a new PR here: https://github.com/apache/arrow/pull/36942
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #36877:
URL: https://github.com/apache/arrow/pull/36877#discussion_r1274389071
##########
python/pyarrow/scalar.pxi:
##########
@@ -1127,4 +1131,4 @@ def scalar(value, type=None, *, from_pandas=None, MemoryPool memory_pool=None):
# retrieve the scalar from the first position
scalar = GetResultValue(array.get().GetScalar(0))
- return Scalar.wrap(scalar)
+ return Scalar.wrap(scalar)
Review Comment:
Could you revert this change too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #36877:
URL: https://github.com/apache/arrow/pull/36877#discussion_r1274388773
##########
python/pyarrow/scalar.pxi:
##########
@@ -113,8 +113,12 @@ cdef class Scalar(_Weakrefable):
else:
with nogil:
check_status(self.wrapped.get().Validate())
-
+
Review Comment:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] danepitkin commented on a diff in pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "danepitkin (via GitHub)" <gi...@apache.org>.
danepitkin commented on code in PR #36877:
URL: https://github.com/apache/arrow/pull/36877#discussion_r1276676467
##########
python/pyarrow/scalar.pxi:
##########
@@ -113,8 +113,12 @@ cdef class Scalar(_Weakrefable):
else:
with nogil:
check_status(self.wrapped.get().Validate())
-
+
def __repr__(self):
+ if isinstance(self, TimestampScalar):
Review Comment:
Good catch! Yes, let's include the timezone when supplied. Let's try and follow the ISO 8601 standard https://en.wikipedia.org/wiki/ISO_8601 and use `%z`. Maybe something like:
```
>>> res = pa.scalar("2000-01-01").cast(pa.timestamp("s"))
>>> res_with_tz = pc.assume_timezone(res, "America/New_York")
>>> str(pc.strftime(res_with_tz, format='%Y-%m-%dT%H:%M:%S%z'))
'2000-01-01T00:00:00-0500'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #36877:
URL: https://github.com/apache/arrow/pull/36877#issuecomment-1657401660
I close this in favor of #36942.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou closed pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou closed pull request #36877: GH-36323: [Python] Fix Timestamp scalar repr error on values outside datetime range
URL: https://github.com/apache/arrow/pull/36877
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org