8000 Revert "refactor: Update display configuration handling in DataFrame" · kosiew/datafusion-python@ba5acc4 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba5acc4

Browse files
committed
Revert "refactor: Update display configuration handling in DataFrame"
This reverts commit 0d5e900.
1 parent 0d5e900 commit ba5acc4

File tree

3 files changed

+12
-73
lines changed

3 files changed

+12
-73
lines changed

python/datafusion/dataframe.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,6 @@ def configure_display(
823823
) -> None:
824824
"""Configure display options for DataFrame representation.
825825
826-
Note: The display configuration is now set at the session context level,
827-
so changes to one DataFrame's display configuration will affect all
828-
DataFrames created from the same context.
829-
830826
Args:
831827
max_table_bytes: Maximum bytes to display for table presentation
832828
(default: 2MB).

python/tests/test_dataframe.py

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,9 +1367,9 @@ def test_min_table_rows_display(ctx):
13671367
row_count = html_output.count("<tr>") - 1 # subtract 1 for the header row
13681368

13691369
# Verify at least min_table_rows rows are displayed
1370-
assert (
1371-
row_count >= custom_min_rows
1372-
), f"Expected at least {custom_min_rows} rows, got {row_count}"
1370+
assert row_count >= custom_min_rows, (
1371+
f"Expected at least {custom_min_rows} rows, got {row_count}"
1372+
)
13731373

13741374
# If data was truncated, "Data truncated" message should be present
13751375
if row_count < rows:
@@ -1542,63 +1542,3 @@ def test_max_table_rows_in_repr(ctx):
15421542
# Should show all rows (20)
15431543
assert lines_all == rows
15441544
assert "Data truncated" not in repr_str_all
1545-
1546-
1547-
def test_session_context_display_config(ctx):
1548-
"""Test that display configuration is shared at session context level."""
1549-
# Create two dataframes from the same context
1550-
batch1 = pa.RecordBatch.from_arrays(
1551-
[pa.array([1, 2, 3]), pa.array([4, 5, 6])],
1552-
names=["a", "b"],
1553-
)
1554-
df1 = ctx.create_dataframe([[batch1]])
1555-
1556-
batch2 = pa.RecordBatch.from_arrays(
1557-
[pa.array([7, 8, 9]), pa.array([10, 11, 12])],
1558-
names=["c", "d"],
1559-
)
1560-
df2 = ctx.create_dataframe([[batch2]])
1561-
1562-
# Set display config on first dataframe
1563-
custom_max_rows = 25
1564-
df1.configure_display(max_table_rows_in_repr=custom_max_rows)
1565-
1566-
# Check that both dataframes have the same config
1567-
assert df1.display_config.max_table_rows_in_repr == custom_max_rows
1568-
assert df2.display_config.max_table_rows_in_repr == custom_max_rows
1569-
1570-
# Change config on second dataframe
1571-
df2.configure_display(max_cell_length=40)
1572-
1573-
# Both dataframes should reflect the change
1574-
assert df1.display_config.max_cell_length == 40
1575-
assert df2.display_config.max_cell_length == 40
1576-
1577-
1578-
def test_session_context_display_config_independence(ctx):
1579-
"""Test that display configurations in different contexts are independent."""
1580-
# Create two contexts with different configurations
1581-
ctx1 = SessionContext()
1582-
ctx2 = SessionContext()
1583-
1584-
# Create dataframes from each context
1585-
batch = pa.RecordBatch.from_arrays(
1586-
[pa.array([1, 2, 3]), pa.array([4, 5, 6])],
1587-
names=["a", "b"],
1588-
)
1589-
df1 = ctx1.create_dataframe([[batch]])
1590-
df2 = ctx2.create_dataframe([[batch]])
1591-
1592-
# Set different display configurations
1593-
df1.configure_display(max_table_rows_in_repr=15)
1594-
df2.configure_display(max_table_rows_in_repr=30)
1595-
1596-
# Verify configurations are independent
1597-
assert df1.display_config.max_table_rows_in_repr == 15
1598-
assert df2.display_config.max_table_rows_in_repr == 30
1599-
1600-
# Create another dataframe from first context
1601-
df3 = ctx1.create_dataframe([[batch]])
1602-
1603-
# It should have the same config as the first dataframe
1604-
assert df3.display_config.max_table_rows_in_repr == 15

src/dataframe.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ pub struct PyDataFrame {
135135

136136
impl PyDataFrame {
137137
/// creates a new PyDataFrame
138-
pub fn new(df: DataFrame, display_config: Arc<DisplayConfig>) -> Self {
138+
pub fn new(df: DataFrame) -> Self {
139139
Self {
140140
df: Arc::new(df),
141-
config: display_config,
141+
config: Arc::new(DisplayConfig::default()),
142142
}
143143
}
144144
}
@@ -858,7 +858,10 @@ impl PyDataFrame {
858858
/// Get the current display configuration
859859
#[getter]
860860
fn display_config(&self) -> PyResult<Py<DisplayConfig>> {
861-
Python::with_gil(|py| Py::new(py, (*self.display_config).clone()))
861+
Python::with_gil(|py| {
862+
let config = (*self.config).clone();
863+
Py::new(py, config)
864+
})
862865
}
863866

864867
/// Update display configuration
@@ -875,7 +878,7 @@ impl PyDataFrame {
875878
max_cell_length: Option<usize>,
876879
max_table_rows_in_repr: Option<usize>,
877880
) {
878-
let mut new_config = (*self.display_config).clone();
881+
let mut new_config = (*self.config).clone();
879882

880883
if let Some(bytes) = max_table_bytes {
881884
new_config.max_table_bytes = bytes;
@@ -893,13 +896,13 @@ impl PyDataFrame {
893896
new_config.max_table_rows_in_repr = rows;
894897
}
895898

896-
self.display_config = Arc::new(new_config);
899+
self.config = Arc::new(new_config);
897900
}
898901

899902
/// Reset display configuration to default values
900903
#[pyo3(text_signature = "($self)")]
901904
fn reset_display_config(&mut self) {
902-
self.display_config = Arc::new(DisplayConfig::default());
905+
self.config = Arc::new(DisplayConfig::default());
903906
}
904907
}
905908

0 commit comments

Comments
 (0)
0