-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: fix to_json on period #61203
base: main
Are you sure you want to change the base?
BUG: fix to_json on period #61203
Conversation
@@ -568,6 +568,19 @@ cdef class BaseOffset: | |||
out += ": " + ", ".join(attrs) | |||
return out | |||
|
|||
def toDict(self) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to implement this here but rather in the C extension code itself; this way of making something JSON serializable takes advantage of an obscure ultrajson method of allowing custom objects to be serialized, and it will be pretty slow compared to direct implementation in our C extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you on implementing it in C extension code
# GH55490 | ||
ser = Series(pd.period_range(start=2021, freq="Y", periods=1)) | ||
result = ser.to_json() | ||
expected = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the JSON representation that users want for a period?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it interesting that the Period
class actually has a freqstr property. This allows us to ignore freq
when running to_json
, which makes sense since freqstr already contains the necessary frequency
information. Additionally, this approach helps resolve the issue.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.