Skip to content
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

Fix period type support for Pandas 2.2.0 #7988

Merged
merged 2 commits into from Jan 22, 2024
Merged

Conversation

LukasMasuch
Copy link
Collaborator

@LukasMasuch LukasMasuch commented Jan 21, 2024

Describe your changes

In Pandas 2.2.0, the "A, H, T, S, L, U, and N are deprecated in favour of the aliases Y, h, min, s, ms, us, and ns."

image

This PR adds support for the new aliases.

Testing Plan

The old e2e tests will cover these cases. But I started a bigger improvement / refactoring related to the period type here: #7987 which will also contain refactored tests.


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-lmasuch sfc-gh-lmasuch changed the title Fix period type support with Pandas 2.2.0 Fix period type support for Pandas 2.2.0 Jan 21, 2024
// Reason is that these types are not supported by moment.js, but also they are not
// very commonly used in practice.
type SupportedPandasOffsetType =
// yearly frequency:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this comment go with "Y"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A and Y are both yearly frequencies

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A is the deprecated alias

// calendar day frequency:
| "D"
// hourly frequency:
| "H" // deprecated alias
Copy link
Contributor

Choose a reason for hiding this comment

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

is "H" a deprecated alias or "h"?
Should it be:

// hourly frequency:
| "H"
// deprecated alias
"h"

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

H is deprecated. The comments are always in the same line of the deprecated alias

type PeriodFrequency =
| SupportedPandasOffsetType
| `${SupportedPandasOffsetType}-${string}`
type PeriodType = `period[${PeriodFrequency}]`

const WEEKDAY_SHORT = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
const formatMs = (duration: number): string =>
Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: looks like this just adds some duration of seconds to 1970-01-01 and then formats it to that specific format.
Should the function name be addMsAndFormat or something different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The value we have is just a millisecond number and we want to format that number. That it gets added to 1970 is more of a detail of the formatting itself (we want it to be formatted to a full date). So I think using addMsAndFormat would be slightly more confusing.

@LukasMasuch LukasMasuch merged commit de8dae4 into develop Jan 22, 2024
40 checks passed
@LukasMasuch LukasMasuch deleted the fix/period-dtype-support branch January 23, 2024 00:21
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
* Fix period type support with Pandas 2.2.x

* Add more comments
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.

None yet

2 participants