Skip to content

Commit

Permalink
Merge pull request #76 from astronomy-commons/sean/fix-from-dataframe…
Browse files Browse the repository at this point in the history
…-index

Fix index not being set correctly in `from_dataframe`
  • Loading branch information
smcguire-cmu authored Nov 28, 2023
2 parents cba6aa5 + 9b3dcba commit b94ee4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lsdb/loaders/dataframe/dataframe_catalog_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _generate_dask_df_and_map(
pixel_dfs.append(df)

# Generate Dask Dataframe with original schema
schema = pd.DataFrame(columns=pixel_dfs[0].columns).astype(pixel_dfs[0].dtypes)
schema = pixel_dfs[0].iloc[:0, :].copy()
ddf, total_rows = self._generate_dask_dataframe(pixel_dfs, schema)

return ddf, ddf_pixel_map, total_rows
Expand Down
3 changes: 3 additions & 0 deletions tests/lsdb/loaders/dataframe/test_from_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pandas as pd
import pytest
from hipscat.catalog import CatalogType
from hipscat.pixel_math.hipscat_id import HIPSCAT_ID_COLUMN
from hipscat.pixel_tree.pixel_node_type import PixelNodeType

import lsdb
Expand Down Expand Up @@ -31,6 +32,8 @@ def test_from_dataframe(small_sky_order1_df, small_sky_order1_catalog):
assert isinstance(catalog, lsdb.Catalog)
# Catalogs have the same information
assert catalog.hc_structure.catalog_info == small_sky_order1_catalog.hc_structure.catalog_info
# Index is set to hipscat index
assert catalog._ddf.index.name == HIPSCAT_ID_COLUMN
# Dataframes have the same data (column data types may differ)
pd.testing.assert_frame_equal(
catalog.compute().sort_index(),
Expand Down

0 comments on commit b94ee4c

Please sign in to comment.