Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions marimo/_data/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,22 @@ def _guess_date_format(
df: nw.DataFrame[Any] = nw.from_native(
data, pass_through=True, eager_only=True
)
col = df[column]
min_date = col.min()
max_date = col.max()

# Get min and max dates using narwhals
min_date = df[column].min()
max_date = df[column].max()
# Handle time-only data

# Handle time-only data
if isinstance(min_date, time) and isinstance(max_date, time):
return "%H:%M:%S", "hoursminutesseconds"

# Calculate the difference in days
time_diff = max_date - min_date
if not hasattr(time_diff, "days"):
days_diff = getattr(time_diff, "days", None)
if days_diff is None:
return self.DEFAULT_DATE_FORMAT, self.DEFAULT_TIME_UNIT

days_diff = time_diff.days

# Choose format based on the range
if days_diff > 365 * 10: # More than 10 years
return "%Y", "year" # Year only
Expand Down