A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: preserve dates when grouping table charts by hour (#11078)
Shahmir Varqhaea86ac926ffb
diff --git a/frontend/src/components/data-table/charts/__tests__/schemas.test.ts b/frontend/src/components/data-table/charts/__tests__/schemas.test.tsindex 0a06e563a9..97d453d39f 100644--- a/frontend/src/components/data-table/charts/__tests__/schemas.test.ts+++ b/frontend/src/components/data-table/charts/__tests__/schemas.test.ts@@ -4,6 +4,31 @@ import { describe, expect, it } from "vitest";import { ChartSchema } from "../schemas";describe("ChartSchema", () => {+ it.each(["hours", "yearmonthdatehours"] as const)(+ "preserves the %s time unit in saved chart configurations",+ (timeUnit) => {+ const column = {+ field: "timestamp",+ selectedDataType: "temporal",+ sort: "ascending",+ timeUnit,+ };+ const config = {+ general: {+ xColumn: { ...column, aggregate: "none" },+ yColumn: { ...column, aggregate: "none" },+ facet: {+ row: { ...column, linkYAxis: true, binned: true, maxbins: 6 },+ column: { ...column, linkXAxis: true, binned: true, maxbins: 6 },+ },+ },+ tooltips: { auto: true, fields: [] },+ };++ expect(ChartSchema.parse(config)).toEqual(config);+ },+ );+it("keeps a known axis column type", () => {const result = ChartSchema.parse({general: { xColumn: { field: "count", type: "integer" } },diff --git a/frontend/src/components/data-table/charts/__tests__/spec.test.ts b/frontend/src/components/data-table/charts/__tests__/spec.test.tsindex 082263ee47..2ff861864c 100644--- a/frontend/src/components/data-table/charts/__tests__/spec.test.ts+++ b/frontend/src/components/data-table/charts/__tests__/spec.test.ts@@ -69,30 +69,33 @@ describe("getAxisEncoding", () => {});});- it("should return correct encoding for temporal field with timeUnit", () => {- const result = getAxisEncoding(- {- field: "date",- selectedDataType: "temporal",- aggregate: NONE_VALUE,- timeUnit: "yearmonth",- },- undefined,- "Date",- undefined,- ChartType.LINE,- );+ it.each(["yearmonth", "hours", "yearmonthdatehours"] as const)(+ "should preserve the %s time unit in temporal axis encodings",+ (timeUnit) => {+ const result = getAxisEncoding(+ {+ field: "date",+ selectedDataType: "temporal",+ aggregate: NONE_VALUE,+ timeUnit,+ },+ undefined,+ "Date",+ undefined,+ ChartType.LINE,+ );- expect(result).toEqual({- field: "date",- type: "temporal",- bin: undefined,- title: "Date",- stack: undefined,- aggregate: undefined,- timeUnit: "yearmonth",- });- });+ expect(result).toEqual({+ field: "date",+ type: "temporal",+ bin: undefined,+ title: "Date",+ stack: undefined,+ aggregate: undefined,+ timeUnit,+ });+ },+ );it("should return correct encoding for categorical field", () => {const result = getAxisEncoding(diff --git a/frontend/src/components/data-table/charts/constants.ts b/frontend/src/components/data-table/charts/constants.tsindex f1647e5e7c..47d30ccec7 100644--- a/frontend/src/components/data-table/charts/constants.ts+++ b/frontend/src/components/data-table/charts/constants.ts@@ -147,17 +147,18 @@ export const TIME_UNIT_DESCRIPTIONS: Record<[title: string, description: string]> = {year: ["Year", "2025"],- quarter: ["Quarter", "Q1 2025"],- month: ["Month", "Jan 2025"],- week: ["Week", "Jan 01, 2025"],- day: ["Day", "Jan 01, 2025"],- hours: ["Hour", "Jan 01, 2025 12:00"],- minutes: ["Minute", "Jan 01, 2025 12:34"],- seconds: ["Second", "Jan 01, 2025 12:34:56"],- milliseconds: ["Millisecond", "Jan 01, 2025 12:34:56.789"],- date: ["Date", "Jan 01, 2025"],- dayofyear: ["Day of Year", "Day 1 of 2025"],+ quarter: ["Quarter of year", "Q1"],+ month: ["Month of year", "Jan"],+ week: ["Week of year", "Week 1"],+ day: ["Day of week", "Sunday"],+ hours: ["Hour of day", "12:00"],+ minutes: ["Minute of hour", "34"],+ seconds: ["Second of minute", "56"],+ milliseconds: ["Millisecond of second", "789"],+ date: ["Day of month", "1"],+ dayofyear: ["Day of year", "Day 1"],yearmonth: ["Year Month", "Jan 2025"],yearmonthdate: ["Year Month Date", "Jan 01, 2025"],+ yearmonthdatehours: ["Year Month Date Hours", "Jan 01, 2025 12:00"],monthdate: ["Month Date", "Jan 01"],};diff --git a/frontend/src/components/data-table/charts/types.ts b/frontend/src/components/data-table/charts/types.tsindex e28d585b03..e548bf16a6 100644--- a/frontend/src/components/data-table/charts/types.ts+++ b/frontend/src/components/data-table/charts/types.ts@@ -40,6 +40,7 @@ export const SINGLE_TIME_UNITS = [export const COMBINED_TIME_UNITS = ["yearmonth","yearmonthdate",+ "yearmonthdatehours","monthdate",] as const;export const TIME_UNITS = [