def _parsed_result() -> Dict[DeclarativeMeta, pd.DataFrame]:
    global _PARSED_RESULT

    if not _PARSED_RESULT:
        _PARSED_RESULT = ca_aggregate_ingest.parse(
            fixtures.as_filepath("QueryResult.xls")
        )

    return _PARSED_RESULT
    def testParse_ParsesHeadAndTail2(self) -> None:
        result = ca_aggregate_ingest.parse(
            fixtures.as_filepath("california_california2018")
        )[CaFacilityAggregate]

        # Assert Head
        expected_head = pd.DataFrame(
            {
                "jurisdiction_name": [
                    "Alameda Sheriff's Dept.",
                    "Alameda Sheriff's Dept.",
                ],
                "facility_name": ["Glen Dyer Jail", "Santa Rita Jail"],
                "average_daily_population": [396, 2185],
                "unsentenced_male_adp": [370, 1589],
                "unsentenced_female_adp": [0, 177],
                "sentenced_male_adp": [26, 370],
                "sentenced_female_adp": [0, 49],
                "report_date": 2 * [datetime.date(2018, 1, 31)],
                "fips": ["06001", "06001"],
                "aggregation_window": 2 * [enum_strings.monthly_granularity],
                "report_frequency": 2 * [enum_strings.monthly_granularity],
            }
        )
        assert_frame_equal(result.head(n=2), expected_head)

        # Assert Tail
        expected_tail = pd.DataFrame(
            {
                "jurisdiction_name": ["Yuba Sheriff's Dept.", "Yuba Sheriff's Dept."],
                "facility_name": ["Yuba County Jail", "Yuba County Jail"],
                "average_daily_population": [342, 339],
                "unsentenced_male_adp": [246, 261],
                "unsentenced_female_adp": [32, 28],
                "sentenced_male_adp": [59, 44],
                "sentenced_female_adp": [5, 6],
                "report_date": [
                    datetime.date(2018, 9, 30),
                    datetime.date(2018, 12, 31),
                ],
                "fips": ["06115", "06115"],
                "aggregation_window": 2 * [enum_strings.monthly_granularity],
                "report_frequency": 2 * [enum_strings.monthly_granularity],
            },
            index=range(1404, 1406),
        )
        assert_frame_equal(result.tail(n=2), expected_tail)
Esempio n. 3
0
from recidiviz.common.constants.aggregate import (
    enum_canonical_strings as enum_strings
)
from recidiviz.ingest.aggregate.regions.ca import ca_aggregate_ingest
from recidiviz.persistence.database.session_factory import SessionFactory
from recidiviz.persistence.database.base_schema import \
    JailsBase
from recidiviz.persistence.database.schema.aggregate import dao
from recidiviz.persistence.database.schema.aggregate.schema import \
    CaFacilityAggregate
from recidiviz.tests.ingest import fixtures
from recidiviz.tests.utils import fakes

# Cache the parsed result between tests since it's expensive to compute
PARSED_RESULT = ca_aggregate_ingest.parse(
    '', fixtures.as_filepath('QueryResult.xls'))
PARSED_RESULT_2 = ca_aggregate_ingest.parse(
    '', fixtures.as_filepath('california_california2018'))


class TestCaAggregateIngest(TestCase):
    """Test that ca_aggregate_ingest correctly parses the CA report file."""

    def setup_method(self, _test_method):
        fakes.use_in_memory_sqlite_database(JailsBase)

    def testParse_ParsesHeadAndTail(self):
        result = PARSED_RESULT[CaFacilityAggregate]

        # Assert Head
        expected_head = pd.DataFrame({
Esempio n. 4
0
import pandas as pd
from pandas.testing import assert_frame_equal
from more_itertools import one
from sqlalchemy import func

from recidiviz.common.constants.aggregate import enum_canonical_strings as enum_strings
from recidiviz.ingest.aggregate.regions.ca import ca_aggregate_ingest
from recidiviz.persistence.database.session_factory import SessionFactory
from recidiviz.persistence.database.base_schema import JailsBase
from recidiviz.persistence.database.schema.aggregate import dao
from recidiviz.persistence.database.schema.aggregate.schema import CaFacilityAggregate
from recidiviz.tests.ingest import fixtures
from recidiviz.tests.utils import fakes

# Cache the parsed result between tests since it's expensive to compute
PARSED_RESULT = ca_aggregate_ingest.parse(
    "", fixtures.as_filepath("QueryResult.xls"))
PARSED_RESULT_2 = ca_aggregate_ingest.parse(
    "", fixtures.as_filepath("california_california2018"))


class TestCaAggregateIngest(TestCase):
    """Test that ca_aggregate_ingest correctly parses the CA report file."""
    def setUp(self) -> None:
        fakes.use_in_memory_sqlite_database(JailsBase)

    def tearDown(self) -> None:
        fakes.teardown_in_memory_sqlite_databases()

    def testParse_ParsesHeadAndTail(self):
        result = PARSED_RESULT[CaFacilityAggregate]
Esempio n. 5
0
from sqlalchemy import func

from recidiviz.common.constants.aggregate import (enum_canonical_strings as
                                                  enum_strings)
from recidiviz.ingest.aggregate.regions.ca import ca_aggregate_ingest
from recidiviz.persistence.database.session_factory import SessionFactory
from recidiviz.persistence.database.base_schema import \
    JailsBase
from recidiviz.persistence.database.schema.aggregate import dao
from recidiviz.persistence.database.schema.aggregate.schema import \
    CaFacilityAggregate
from recidiviz.tests.ingest import fixtures
from recidiviz.tests.utils import fakes

# Cache the parsed result between tests since it's expensive to compute
PARSED_RESULT = ca_aggregate_ingest.parse(
    '', fixtures.as_filepath('QueryResult.xls'))


class TestCaAggregateIngest(TestCase):
    """Test that ca_aggregate_ingest correctly parses the CA report file."""
    def setup_method(self, _test_method):
        fakes.use_in_memory_sqlite_database(JailsBase)

    def testParse_ParsesHeadAndTail(self):
        result = PARSED_RESULT[CaFacilityAggregate]

        # Assert Head
        expected_head = pd.DataFrame({
            'jurisdiction_name':
            ['Alameda Sheriff\'s Dept.', 'Alameda Sheriff\'s Dept.'],
            'facility_name': ['Glen Dyer Jail', 'Santa Rita Jail'],