policyengine 3.1.4__py3-none-any.whl → 3.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- policyengine/__pycache__/__init__.cpython-313.pyc +0 -0
- policyengine/core/dataset.py +21 -5
- {policyengine-3.1.4.dist-info → policyengine-3.1.5.dist-info}/METADATA +1 -1
- {policyengine-3.1.4.dist-info → policyengine-3.1.5.dist-info}/RECORD +7 -7
- {policyengine-3.1.4.dist-info → policyengine-3.1.5.dist-info}/WHEEL +0 -0
- {policyengine-3.1.4.dist-info → policyengine-3.1.5.dist-info}/licenses/LICENSE +0 -0
- {policyengine-3.1.4.dist-info → policyengine-3.1.5.dist-info}/top_level.txt +0 -0
|
Binary file
|
policyengine/core/dataset.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from uuid import uuid4
|
|
2
2
|
|
|
3
|
+
import numpy as np
|
|
3
4
|
import pandas as pd
|
|
4
5
|
from microdf import MicroDataFrame
|
|
5
6
|
from pydantic import BaseModel, ConfigDict, Field
|
|
@@ -100,7 +101,7 @@ def map_to_entity(
|
|
|
100
101
|
target_entity: str,
|
|
101
102
|
person_entity: str = "person",
|
|
102
103
|
columns: list[str] | None = None,
|
|
103
|
-
values:
|
|
104
|
+
values: np.ndarray | None = None,
|
|
104
105
|
how: str = "sum",
|
|
105
106
|
) -> MicroDataFrame:
|
|
106
107
|
"""Map data from source entity to target entity using join keys.
|
|
@@ -143,6 +144,9 @@ def map_to_entity(
|
|
|
143
144
|
# Get source data (convert to plain DataFrame to avoid weighted operations during mapping)
|
|
144
145
|
source_df = pd.DataFrame(entity_data[source_entity])
|
|
145
146
|
|
|
147
|
+
# Track if we should return a MicroSeries (values is a numpy array, not a list)
|
|
148
|
+
return_series = values is not None
|
|
149
|
+
|
|
146
150
|
# Handle values parameter - create a temporary column with the provided values
|
|
147
151
|
if values is not None:
|
|
148
152
|
if len(values) != len(source_df):
|
|
@@ -166,7 +170,10 @@ def map_to_entity(
|
|
|
166
170
|
|
|
167
171
|
# Same entity - return as is
|
|
168
172
|
if source_entity == target_entity:
|
|
169
|
-
|
|
173
|
+
result = MicroDataFrame(source_df, weights=target_weight)
|
|
174
|
+
if return_series:
|
|
175
|
+
return result["__mapped_value"]
|
|
176
|
+
return result
|
|
170
177
|
|
|
171
178
|
# Get target data and key
|
|
172
179
|
target_df = entity_data[target_entity]
|
|
@@ -225,7 +232,10 @@ def map_to_entity(
|
|
|
225
232
|
# Fill NaN with 0 for groups with no members in source entity
|
|
226
233
|
result[agg_cols] = result[agg_cols].fillna(0)
|
|
227
234
|
|
|
228
|
-
|
|
235
|
+
result_df = MicroDataFrame(result, weights=target_weight)
|
|
236
|
+
if return_series:
|
|
237
|
+
return result_df["__mapped_value"]
|
|
238
|
+
return result_df
|
|
229
239
|
|
|
230
240
|
# Group entity to person: expand group-level data to person level
|
|
231
241
|
if source_entity != person_entity and target_entity == person_entity:
|
|
@@ -284,7 +294,10 @@ def map_to_entity(
|
|
|
284
294
|
f"Unsupported aggregation method for group->person: {how}. Use 'project' or 'divide'."
|
|
285
295
|
)
|
|
286
296
|
|
|
287
|
-
|
|
297
|
+
result_df = MicroDataFrame(result, weights=target_weight)
|
|
298
|
+
if return_series:
|
|
299
|
+
return result_df["__mapped_value"]
|
|
300
|
+
return result_df
|
|
288
301
|
|
|
289
302
|
# Group to group: go through person table
|
|
290
303
|
if source_entity != person_entity and target_entity != person_entity:
|
|
@@ -408,7 +421,10 @@ def map_to_entity(
|
|
|
408
421
|
# Fill NaN with 0
|
|
409
422
|
result[agg_cols] = result[agg_cols].fillna(0)
|
|
410
423
|
|
|
411
|
-
|
|
424
|
+
result_df = MicroDataFrame(result, weights=target_weight)
|
|
425
|
+
if return_series:
|
|
426
|
+
return result_df["__mapped_value"]
|
|
427
|
+
return result_df
|
|
412
428
|
|
|
413
429
|
raise ValueError(
|
|
414
430
|
f"Unsupported mapping from {source_entity} to {target_entity}"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
policyengine/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
policyengine/__pycache__/__init__.cpython-313.pyc,sha256=
|
|
2
|
+
policyengine/__pycache__/__init__.cpython-313.pyc,sha256=i0if-AwQ3fDLDZnEs_L7YxJXPz-_BGDRJstrY56T1cU,175
|
|
3
3
|
policyengine/core/__init__.py,sha256=KBVhkqzkvjWLDDwk96vquQKL63ZFuLen5AzBOBnO9pg,912
|
|
4
|
-
policyengine/core/dataset.py,sha256=
|
|
4
|
+
policyengine/core/dataset.py,sha256=iJr9-J6w11uMRYy3EEJO9Gveku1m71AA1yzeo-0SiCs,16094
|
|
5
5
|
policyengine/core/dataset_version.py,sha256=6KeFCRGQto_Yyl4QY4Vo2JFythjaXrNAOHQiwRGESyM,378
|
|
6
6
|
policyengine/core/dynamic.py,sha256=ng9BjDzxdwjJ0e7zoqXFmq33E1SRbaaPYfW7pjRSSzI,1641
|
|
7
7
|
policyengine/core/output.py,sha256=cCW4vbzkLdQaT_nJTyDJBl7Hubm7nZeRuR7aVG1dKvg,643
|
|
@@ -32,8 +32,8 @@ policyengine/utils/__init__.py,sha256=1X-VYAWLyB9A0YRHwsGWrqQHns1WfeZ7ISC6DMU5my
|
|
|
32
32
|
policyengine/utils/dates.py,sha256=HnAqyl8S8EOYp8ibsnMTmECYoDWCSqwL-7A2_qKgxSc,1510
|
|
33
33
|
policyengine/utils/parametric_reforms.py,sha256=4P3U39-4pYTU4BN6JjgmVLUkCkBhRfZJ6UIWTlsjyQE,1155
|
|
34
34
|
policyengine/utils/plotting.py,sha256=ZAzTWz38vIaW0c3Nt4Un1kfrNoXLyHCDd1pEJIlsRg4,5335
|
|
35
|
-
policyengine-3.1.
|
|
36
|
-
policyengine-3.1.
|
|
37
|
-
policyengine-3.1.
|
|
38
|
-
policyengine-3.1.
|
|
39
|
-
policyengine-3.1.
|
|
35
|
+
policyengine-3.1.5.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
36
|
+
policyengine-3.1.5.dist-info/METADATA,sha256=OrYJJBzGq6CZeokXm7gCprOYUPPJe0d4unqvivTPyXU,45889
|
|
37
|
+
policyengine-3.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
38
|
+
policyengine-3.1.5.dist-info/top_level.txt,sha256=_23UPobfkneHQkpJ0e0OmDJfhCUfoXj_F2sTckCGOH4,13
|
|
39
|
+
policyengine-3.1.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|