-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support interchange protocol #3340
Changes from all commits
142086a
55df47b
194a564
088cb08
03c1717
7dd9ff6
bbfdadb
ad48c8a
a0bd3f7
8edcf14
22df733
fa37b56
b5c4ff8
064b2e6
3f32596
f4f3317
1103aa9
338e119
5a44bed
73f35d5
63c21ee
0e9586f
9f1927f
9c4aedb
e7e84f5
30e1002
1985028
b8584ee
5b2532e
4897344
8117fe6
3812e5f
6494ef4
991c343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
numpy~=1.20.0 | ||
pandas~=1.2.0 | ||
polars~=0.17.0 | ||
pyarrow~=12.0.0 | ||
matplotlib~=3.3.0 | ||
scipy~=1.7.0 | ||
statsmodels~=0.12.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
"""Utility functions, mostly for internal use.""" | ||
from __future__ import annotations | ||
|
||
import os | ||
import inspect | ||
import warnings | ||
|
@@ -894,3 +896,19 @@ def _disable_autolayout(): | |
def _version_predates(lib: ModuleType, version: str) -> bool: | ||
"""Helper function for checking version compatibility.""" | ||
return Version(lib.__version__) < Version(version) | ||
|
||
|
||
def try_convert_to_pandas(data: object | None) -> pd.DataFrame: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just because |
||
if data is None: | ||
return None | ||
elif isinstance(data, pd.DataFrame): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this guard important? will passing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, thanks, it is in-fact a no-op However, seaborn still supports versions of pandas older than those which support the interchange protocol, so I introduced this to keep it a no-op in such cases |
||
return data | ||
elif hasattr(data, "__dataframe__") and _version_predates(pd, "2.0.2"): | ||
msg = ( | ||
"Interchanging to pandas requires at least pandas version '2.0.2'. " | ||
"Please upgrade pandas to at least version '2.0.2'." | ||
) | ||
raise RuntimeError(msg) | ||
elif hasattr(data, "__dataframe__"): | ||
return pd.api.interchange.from_dataframe(data) | ||
return data |
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.
if
val
is a non-pandas Series, then checkingval in data
will throwValueError