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

BUG: Modin datetime64 values not compatible with Seaborn #7407

Open
3 tasks done
gtomitsuka opened this issue Oct 23, 2024 · 1 comment
Open
3 tasks done

BUG: Modin datetime64 values not compatible with Seaborn #7407

gtomitsuka opened this issue Oct 23, 2024 · 1 comment
Labels
bug 🦗 Something isn't working Triage 🩹 Issues that need triage

Comments

@gtomitsuka
Copy link

gtomitsuka commented Oct 23, 2024

Modin version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest released version of Modin.

  • I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow this guide.)

Reproducible Example

import modin.pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

dates = pd.date_range(
    start=pd.Timestamp('2024-01-01', unit='ns'),
    end=pd.Timestamp('2024-03-01', unit='ns'),
    freq='D'
).astype('datetime64[s]')

data = {
    'date': dates,
    'value': np.random.normal(100, 15, len(dates)),
    'category': np.random.choice(['A', 'B', 'C'], len(dates)),
    'trend': np.linspace(80, 120, len(dates)) + np.random.normal(0, 5, len(dates))
}
df = pd.DataFrame(data)

print(f"DataFrame date column dtype: {df['date'].dtype}")

sns.set_style("whitegrid")

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10))

sns.lineplot(data=df, x='date', y='value', hue='category', ax=ax1)
ax1.set_title('Time Series by Category (datetime64[ns])')
ax1.set_xlabel('Date')
ax1.set_ylabel('Value')
ax1.tick_params(axis='x', rotation=45)

df['week'] = df['date'].dt.strftime('%W')
sns.boxplot(data=df, x='week', y='trend', ax=ax2)
ax2.set_title('Weekly Distribution of Trend')
ax2.set_xlabel('Week Number')
ax2.set_ylabel('Trend Value')
ax2.tick_params(axis='x', rotation=45)

plt.tight_layout()

print("\nDatetime Information:")
print(f"First timestamp: {df['date'].iloc[0]}")
print(f"Last timestamp: {df['date'].iloc[-1]}")
print(f"Time resolution: {df['date'].iloc[0].resolution}")

print("\nSummary Statistics by Category:")
summary = df.set_index('date').groupby('category')['value'].describe()
print(summary)

plt.show()

Issue Description

Seaborn calls the __dataframe__() endpoint, which triggers Modin's implementation of the DataFrame interchange protocol, but that doesn't support any granularity of datetime64. This is necessary for high-precision charting.

Expected Behavior

The following two plots are generated:
image

Error Logs

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/seaborn/_core/data.py](https://localhost:8080/#) in convert_dataframe_to_pandas(data)
    312         # in Plot.add(). But noting here in case this seems to be a bottleneck.
--> 313         return pd.api.interchange.from_dataframe(data)
    314     except Exception as err:

13 frames
NotImplementedError: Data type datetime64[s] not supported by the dataframe exchange protocol

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/seaborn/_core/data.py](https://localhost:8080/#) in convert_dataframe_to_pandas(data)
    317             "to a pandas DataFrame. See traceback above for details."
    318         )
--> 319         raise RuntimeError(msg) from err

RuntimeError: Encountered an exception when converting data source to a pandas DataFrame. See traceback above for details.

Installed Versions

INSTALLED VERSIONS

commit : 3e951a6
python : 3.10.12.final.0
python-bits : 64
OS : Linux
OS-release : 6.1.85+
Version : #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

Modin dependencies

modin : 0.32.0
ray : 2.38.0
dask : 2024.8.2
distributed : None

pandas dependencies

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.2
dateutil : 2.8.2
setuptools : 75.1.0
pip : 24.1.2
Cython : 3.0.11
pytest : 7.4.4
hypothesis : None
sphinx : 5.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.4
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.10
jinja2 : 3.1.4
IPython : 7.34.0
pandas_datareader : 0.10.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : 1.4.2
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.6.1
gcsfs : 2024.6.1
matplotlib : 3.7.1
numba : 0.60.0
numexpr : 2.10.1
odfpy : None
openpyxl : 3.1.5
pandas_gbq : 0.23.2
pyarrow : 16.1.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : 2.0.36
tables : 3.8.0
tabulate : 0.9.0
xarray : 2024.9.0
xlrd : 2.0.1
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
Colab

@gtomitsuka gtomitsuka added bug 🦗 Something isn't working Triage 🩹 Issues that need triage labels Oct 23, 2024
@gtomitsuka
Copy link
Author

Update: I tested using the main branch of modin, still happens.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🦗 Something isn't working Triage 🩹 Issues that need triage
Projects
None yet
Development

No branches or pull requests

1 participant