Skip to content
Draft
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,32 @@ def _compute_profiles(
raise NotImplementedError(profile_type)
return ColumnProfileResult(**results)

def _get_format_options(self) -> FormatOptions | None:
"""
Get format options based on current Python/NumPy display settings.
Returns None if using default formatting.

Subclasses can override this to provide backend-specific format options.
For example, to respect Python display settings:

import pandas as pd
precision = pd.get_option('display.precision') # Default: 6

# Calculate max_integral_digits based on threshold for scientific notation
# Similar to R's scipen option
max_integral = 7 # Default threshold

return FormatOptions(
large_num_digits=precision,
small_num_digits=precision,
max_integral_digits=max_integral,
max_value_length=1000,
thousands_sep=None # or ',' if desired
)
"""
# For now, return None to use frontend defaults
return None

def get_state(self, _unused):
self._recompute_if_needed()

Expand Down Expand Up @@ -635,6 +661,7 @@ def get_state(self, _unused):
row_filters=self.state.row_filters,
sort_keys=self.state.sort_keys,
supported_features=self.FEATURES,
format_options=self._get_format_options(),
)

def _recompute(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2024-2025 Posit Software, PBC. All rights reserved.
# Copyright (C) 2024-2026 Posit Software, PBC. All rights reserved.
# Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
#

Expand Down Expand Up @@ -362,6 +362,11 @@ class BackendState(BaseModel):
description="Optional experimental parameter to provide an explanation when connected=false. This parameter may change.",
)

format_options: Optional[FormatOptions] = Field(
default=None,
description="Optional formatting options provided by the backend for displaying data values",
)


class ColumnSchema(BaseModel):
"""
Expand Down
4 changes: 4 additions & 0 deletions positron/comms/data_explorer-backend-openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@
"error_message": {
"type": "string",
"description": "Optional experimental parameter to provide an explanation when connected=false. This parameter may change."
},
"format_options": {
"description": "Optional formatting options provided by the backend for displaying data values",
"$ref": "#/components/schemas/format_options"
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions positron/comms/data_explorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

## Backend Methods

### get_state

The `get_state` method returns the current backend state including table metadata and optional formatting options.

#### Format Options

The backend can optionally provide `format_options` in the state to control how numeric values are displayed. This allows backends to respect language-specific settings (e.g., R's `scipen` option).

Format options include:
* `large_num_digits`: Fixed number of decimal places for numbers over 1 or in scientific notation
* `small_num_digits`: Fixed number of decimal places for small numbers and threshold for scientific notation
* `max_integral_digits`: Maximum integral digits before switching to scientific notation
* `max_value_length`: Maximum formatted value length for truncation
* `thousands_sep`: Optional thousands separator character

If format_options is not provided, the frontend will use sensible defaults.

### get_data_values

Non-special values are returned formatted as strings.
Expand Down
Loading
Loading