Skip to content

Commit 955c01e

Browse files
authored
fix: column dtypes in empty dfs... (#24)
Co-authored-by: Michał Sośnicki <michal.sosnicki@neptune.ai>
1 parent 21fac4e commit 955c01e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/neptune_query/internal/output_format.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ def _restore_path_column_names(
461461
Restores colum names in the DF based on the mapping.
462462
"""
463463

464+
# No columns to rename, simply ensure the dtype of the path column changes from categorical int to str
465+
if df.columns.empty:
466+
if isinstance(df.columns, pd.MultiIndex):
467+
df.columns = df.columns.set_levels(df.columns.get_level_values("path").astype(str), level="path")
468+
else:
469+
df.columns = df.columns.astype(str)
470+
return df
471+
464472
# We need to reverse the mapping to index -> column name
465473
if type_suffix:
466474
reverse_mapping = {index: f"{path}:{type_suffix}" for path, index in path_mapping.items()}

tests/unit/internal/test_output_format.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,10 @@ def test_create_empty_metrics_dataframe(
930930

931931
# With previews or timestamps, MultiIndex columns are returned
932932
if include_preview or timestamp_column_name:
933-
expected_df.columns = pd.MultiIndex.from_tuples([], names=[None, None])
933+
expected_df.columns = pd.MultiIndex.from_product([[], ["value"]], names=[None, None])
934+
# the comparator seems not to delve into the exact column names on the 2nd level when the 1st level is empty..
934935

935-
pd.testing.assert_frame_equal(df, expected_df, check_column_type=False)
936+
pd.testing.assert_frame_equal(df, expected_df)
936937

937938

938939
@pytest.mark.parametrize("timestamp_column_name", [None, "absolute"])
@@ -956,9 +957,9 @@ def test_create_empty_series_dataframe(timestamp_column_name: str):
956957
)
957958

958959
if timestamp_column_name:
959-
expected_df.columns = pd.MultiIndex.from_tuples([], names=[None, None])
960+
expected_df.columns = pd.MultiIndex.from_product([[], ["value"]], names=[None, None])
960961

961-
pd.testing.assert_frame_equal(df, expected_df, check_index_type=False, check_column_type=False)
962+
pd.testing.assert_frame_equal(df, expected_df)
962963

963964

964965
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)