Coverage for tests / test_schemaUtils.py: 25%
22 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-28 09:06 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-28 09:06 +0000
1# This file is part of pipe_tasks.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import os
23import unittest
25import pandas as pd
27from lsst.pipe.tasks.schemaUtils import readSdmSchemaFile, make_empty_catalog, convertDataFrameToSdmSchema
30class TestSchemaUtils(unittest.TestCase):
32 def test_make_empty_catalog(self):
33 """Check that an empty catalog has the correct format.
34 """
35 schemaFile = os.path.join("${SDM_SCHEMAS_DIR}", "yml", "apdb.yaml")
36 schema = readSdmSchemaFile(schemaFile)
38 tableNames = ["DiaObject", "DiaSource", "DiaForcedSource"]
39 for tableName in tableNames:
40 emptyDiaObjects = make_empty_catalog(schema, tableName=tableName)
41 self.assertTrue(emptyDiaObjects.empty)
43 emptyColumns = set(emptyDiaObjects.columns)
44 self.assertIn("ra", emptyColumns)
45 self.assertIn("dec", emptyColumns)
46 self.assertIn("diaObjectId", emptyColumns)
48 emptyDf = pd.DataFrame(columns=["diaObjectId",])
49 emptyDf.set_index("diaObjectId")
50 convertedEmptyDiaObjects = convertDataFrameToSdmSchema(schema, emptyDf, tableName=tableName)
51 # TODO: we have no tests of convertDataFrameToSdmSchema, so it's dangerous to use it as an oracle.
52 emptyTypes = dict(zip(emptyDiaObjects.columns, emptyDiaObjects.dtypes))
53 convertedEmptyTypes = dict(zip(convertedEmptyDiaObjects.columns, convertedEmptyDiaObjects.dtypes))
54 self.assertEqual(emptyTypes, convertedEmptyTypes)