Transforms
enrichsdk.contrib.transforms
→
Standard transforms that can be directly included in any pipeline.
FileOperations(*args, **kwargs)
→
Bases: FileOperationsBase
FileOperations performs a number of operations on files generated by pipelines.
The transform takes a list of actions. The only action type
supported for now is copy
. Each copy task requires source,
destination, and instruction on what to do with existing file.
Example::
{
"transform": "FileOperations",
"enable": true,
"dependencies": {
....
},
"args": {
"actions": [
{
"action": "copy",
"src": "%(output)s/%(runid)s/profile.sqlite",
"dst": "%(data_root)s/shared/campaigns/profile_daily/profile.sqlite",
"backupsuffix": ".backup"
}
]
}
}
Source code in enrichsdk/contrib/transforms/fileops/__init__.py
JSONSink(*args, **kwargs)
→
Bases: Sink
Store a 'dict' frame that is present in the state into a file.
Params are meant to be passed as parameter to update_frame.
Example configuration::
"args": {
"sink": {
'test': {
'frametype': 'dict',
'filename': '%(output)s/%(runid)s/mytestoutput.json',
'params': {}
}
}
}
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
preload_clean_args(args)
→
Clean when the spec is loaded...
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
process(state)
→
Store the dictionary 'frames' in the state in files.
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
validate_args(what, state)
→
An extra check on the arguments to make sure it is consistent with the specification
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
JSONSource(*args, **kwargs)
→
Bases: Source
Load a file into a 'dict' frame in the state.
Params are meant to be passed as parameter to update_frame.
Example configuration::
...
"args": {
"source": {
'hello': {
'frametype': 'dict',
'filename': '%(data_root)s/shared/hello.json',
'params': {}
}
}
}
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
preload_clean_args(args)
→
Check if the args are consistent with the specification.
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
process(state)
→
Load the json files into 'dict' frames and store them in the state.
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
validate_args(what, state)
→
Double check the arguments
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
validate_results(what, state)
→
Check to make sure that the execution completed correctly
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
PQExport(*args, **kwargs)
→
Bases: Sink
Parquet export for dataframes.
The configuration requires a list of exports, each of which specifies a pattern for the frame name::
'conf': {
'args': {
"exports": [
{
"name": "%(frame)s_pq",
"type": "pq", # optional. Default is pq
"frames": ["cars"],
"filename": "%(output)s/%(runid)s/%(frame)s.pq",
"params": {
# parquet parameters.
# "compression": 'gzip'
# "engine": 'auto'
# "index" :None,
# "partition_cols": None
}
}
]
}
}
Source code in enrichsdk/contrib/transforms/pqexport/__init__.py
process(state)
→
Export frames as parquet files as shown in the example.
Source code in enrichsdk/contrib/transforms/pqexport/__init__.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
SQLExport(*args, **kwargs)
→
Bases: Sink
Export dataframes into the SQL database. Args specify what and how the export should happen.
The transform args provides the specification:
* exports: A list of files that must be exported. Each is a
dictionary with the following elements:
* name: Name of this export. Used for internal tracking and notifications.
* filename: Output filename. Can refer to other global attributes such as `data_root`, `enrich_root_dir` etc
* type: Type of the export. Only `sqlite` supported for now
* frames: List of frames of the type `pandas` that should
exported as part of this file
Example::
....
"transforms": {
"enabled": [
...
{
"transform": "SQLExport",
"args": {
"exports": [
{
"type": "sqlite",
"filename": "%(output)s/cars.sqlite",
"frames": ["cars", "alpha"]
},
...
]
},
...
}
...
}
}
Source code in enrichsdk/contrib/transforms/sqlexport/__init__.py
preload_clean_args(args)
→
Enforce the args specification given in the example above
Source code in enrichsdk/contrib/transforms/sqlexport/__init__.py
process(state)
→
Execute the export specification.
Source code in enrichsdk/contrib/transforms/sqlexport/__init__.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
TableSink(*args, **kwargs)
→
Bases: Sink
Transform to dump dataframes in state into files.
Parameters specific to this module include:
* sink: A dictionary of dataframe names and how to output them. It has a number of attributes:
* type: Output type. Only 'table' value is supported for this
option right now.
* filename: Output filename. You can use default parameters such
runid
The name of the dataframe can be a regular expression allowing you
specify a simple rule for arbitrary number of frames.
Example::
....
"transforms": {
"enabled": [
...
{
"transform": "TableSink",
"args": {
"sink": {
"article": {
"frametype": "pandas",
"filename": "%(output)s/%(runid)s/article.csv",
"params": {
"sep": "|"
}
},
...
}
}
...
}
]
}
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
preload_clean_args(args)
→
Check to make sure that the arguments is consistent with the specification mentioned above
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
process(state)
→
Execute the tablesink specification
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
validate_args(what, state)
→
Extra validation of the arguments
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
TableSource(*args, **kwargs)
→
Bases: Source
Load csv/other files into pandas dataframes.
Parameters specific to this module include:
* source: A dictionary of dataframe names and how to
load them. It has a number of attributes:
* type: Output type. Only 'table' value is
supported for this option.
* filename: Output filename. You can use default
parameters such runid
* params: Params are arguments to [pandas read_csv](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html)
Example::
....
"transforms": {
"enabled": [
{
"transform": "TableSink",
"args": {
"source": {
"article": {
"type": "file",
"filename": "%(data)s/ArticleData.csv",
"params": {
"delimiter": "|",
"dtype": {
"sku": "category",
"mc_code": "int64",
"sub_class": "category",
"priority": "float64"
...
}
}
}
}
...
}
}
...
]
}
Source code in enrichsdk/contrib/transforms/tablesource/__init__.py
clean(state)
→
preload_clean_args(args)
→
Clean when the spec is loaded...
Source code in enrichsdk/contrib/transforms/tablesource/__init__.py
process(state)
→
Load file...
Source code in enrichsdk/contrib/transforms/tablesource/__init__.py
fileops
→
FileOperations(*args, **kwargs)
→
Bases: FileOperationsBase
FileOperations performs a number of operations on files generated by pipelines.
The transform takes a list of actions. The only action type
supported for now is copy
. Each copy task requires source,
destination, and instruction on what to do with existing file.
Example::
{
"transform": "FileOperations",
"enable": true,
"dependencies": {
....
},
"args": {
"actions": [
{
"action": "copy",
"src": "%(output)s/%(runid)s/profile.sqlite",
"dst": "%(data_root)s/shared/campaigns/profile_daily/profile.sqlite",
"backupsuffix": ".backup"
}
]
}
}
Source code in enrichsdk/contrib/transforms/fileops/__init__.py
jsonsink
→
JSONSink(*args, **kwargs)
→
Bases: Sink
Store a 'dict' frame that is present in the state into a file.
Params are meant to be passed as parameter to update_frame.
Example configuration::
"args": {
"sink": {
'test': {
'frametype': 'dict',
'filename': '%(output)s/%(runid)s/mytestoutput.json',
'params': {}
}
}
}
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
preload_clean_args(args)
→
Clean when the spec is loaded...
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
process(state)
→
Store the dictionary 'frames' in the state in files.
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
validate_args(what, state)
→
An extra check on the arguments to make sure it is consistent with the specification
Source code in enrichsdk/contrib/transforms/jsonsink/__init__.py
jsonsource
→
JSONSource(*args, **kwargs)
→
Bases: Source
Load a file into a 'dict' frame in the state.
Params are meant to be passed as parameter to update_frame.
Example configuration::
...
"args": {
"source": {
'hello': {
'frametype': 'dict',
'filename': '%(data_root)s/shared/hello.json',
'params': {}
}
}
}
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
preload_clean_args(args)
→
Check if the args are consistent with the specification.
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
process(state)
→
Load the json files into 'dict' frames and store them in the state.
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
validate_args(what, state)
→
Double check the arguments
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
validate_results(what, state)
→
Check to make sure that the execution completed correctly
Source code in enrichsdk/contrib/transforms/jsonsource/__init__.py
pqexport
→
PQExport(*args, **kwargs)
→
Bases: Sink
Parquet export for dataframes.
The configuration requires a list of exports, each of which specifies a pattern for the frame name::
'conf': {
'args': {
"exports": [
{
"name": "%(frame)s_pq",
"type": "pq", # optional. Default is pq
"frames": ["cars"],
"filename": "%(output)s/%(runid)s/%(frame)s.pq",
"params": {
# parquet parameters.
# "compression": 'gzip'
# "engine": 'auto'
# "index" :None,
# "partition_cols": None
}
}
]
}
}
Source code in enrichsdk/contrib/transforms/pqexport/__init__.py
process(state)
→
Export frames as parquet files as shown in the example.
Source code in enrichsdk/contrib/transforms/pqexport/__init__.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
sqlexport
→
SQLExport(*args, **kwargs)
→
Bases: Sink
Export dataframes into the SQL database. Args specify what and how the export should happen.
The transform args provides the specification:
* exports: A list of files that must be exported. Each is a
dictionary with the following elements:
* name: Name of this export. Used for internal tracking and notifications.
* filename: Output filename. Can refer to other global attributes such as `data_root`, `enrich_root_dir` etc
* type: Type of the export. Only `sqlite` supported for now
* frames: List of frames of the type `pandas` that should
exported as part of this file
Example::
....
"transforms": {
"enabled": [
...
{
"transform": "SQLExport",
"args": {
"exports": [
{
"type": "sqlite",
"filename": "%(output)s/cars.sqlite",
"frames": ["cars", "alpha"]
},
...
]
},
...
}
...
}
}
Source code in enrichsdk/contrib/transforms/sqlexport/__init__.py
preload_clean_args(args)
→
Enforce the args specification given in the example above
Source code in enrichsdk/contrib/transforms/sqlexport/__init__.py
process(state)
→
Execute the export specification.
Source code in enrichsdk/contrib/transforms/sqlexport/__init__.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
tablesink
→
TableSink(*args, **kwargs)
→
Bases: Sink
Transform to dump dataframes in state into files.
Parameters specific to this module include:
* sink: A dictionary of dataframe names and how to output them. It has a number of attributes:
* type: Output type. Only 'table' value is supported for this
option right now.
* filename: Output filename. You can use default parameters such
runid
The name of the dataframe can be a regular expression allowing you
specify a simple rule for arbitrary number of frames.
Example::
....
"transforms": {
"enabled": [
...
{
"transform": "TableSink",
"args": {
"sink": {
"article": {
"frametype": "pandas",
"filename": "%(output)s/%(runid)s/article.csv",
"params": {
"sep": "|"
}
},
...
}
}
...
}
]
}
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
preload_clean_args(args)
→
Check to make sure that the arguments is consistent with the specification mentioned above
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
process(state)
→
Execute the tablesink specification
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
validate_args(what, state)
→
Extra validation of the arguments
Source code in enrichsdk/contrib/transforms/tablesink/__init__.py
tablesource
→
TableSource(*args, **kwargs)
→
Bases: Source
Load csv/other files into pandas dataframes.
Parameters specific to this module include:
* source: A dictionary of dataframe names and how to
load them. It has a number of attributes:
* type: Output type. Only 'table' value is
supported for this option.
* filename: Output filename. You can use default
parameters such runid
* params: Params are arguments to [pandas read_csv](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html)
Example::
....
"transforms": {
"enabled": [
{
"transform": "TableSink",
"args": {
"source": {
"article": {
"type": "file",
"filename": "%(data)s/ArticleData.csv",
"params": {
"delimiter": "|",
"dtype": {
"sku": "category",
"mc_code": "int64",
"sub_class": "category",
"priority": "float64"
...
}
}
}
}
...
}
}
...
]
}
Source code in enrichsdk/contrib/transforms/tablesource/__init__.py
clean(state)
→
preload_clean_args(args)
→
Clean when the spec is loaded...
Source code in enrichsdk/contrib/transforms/tablesource/__init__.py
process(state)
→
Load file...
Source code in enrichsdk/contrib/transforms/tablesource/__init__.py
enrichsdk.contrib.lib.transforms
→
AnomaliesBase(*args, **kwargs)
→
Bases: Compute
Compute anomalies given a dataframe with columns
Features of transform baseclass include:
* Flexible configuration
* Highlevel specification of columns combinations and detection strategy
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
get_dataset_s3(spec, paths)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
get_handlers(spec)
→
get_profile()
→
Read the profile json from API
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
preprocess_spec(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 |
|
process_spec_default(data, spec)
→
Handle one specification at a time..
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
ChangePointDetectorBase(*args, **kwargs)
→
Bases: Compute
Take a timeseries signal and identify changepoints in the signal
Features of transform baseclass include: * Flexible configuration * Highlevel specification of change point detection: * specified data source or custom method to generate one * generic change point detection method or custom defined ones
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
|
process_spec_default(spec, data)
→
Run the default change point detection
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
ClassifierBase(*args, **kwargs)
→
Bases: Compute
Take a training dataset and one or more eval datasets Builds a classification model using the training dataset Applies the model on the eval dataset(s) and generates predictions
Features of transform baseclass include: * Flexible configuration * Highlevel specification of steps in ML classification flow: * specify multiple datasets (one for training, one or more for evaluation) * specify optional dataset prep methods * specify training model details with support for imbalanced datasets * specify evaluation strategy on one or more datasets
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
do_training(profilespec, modelspec, X, y, model, cv, metric)
→
Train a model given a dataset and a pipeline
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
|
get_classifier_pipeline(model)
→
Construct the classifier pipeline 1. resampling 2. classifier model
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
get_handlers(spec)
→
load_sources(profilespec)
→
Load all the data sources
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
make_predictions(profilespec, data, classifiers, artifacts)
→
Generate predictions for the various eval datasets
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
|
prep_data(profilespec, data, artifacts)
→
Do any data prep needed We may need to do data scaling, normalization, etc. here Any artifacts of the prep that will be needed by the prediction stage must be returned in this function
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 |
|
store_metadata(spec, results)
→
Store all the metadata for the full run
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
train_models(profilespec, data)
→
Model training
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
|
DataObserverBase(*args, **kwargs)
→
Bases: Compute
Monitor an input data source given a spec
Features of transform baseclass include: * Flexible configuration * Highlevel specification of observability: * specified data source * custom defined testing conditions for observability * custom defined output of observability results * notification of observability results on success/failure
Source code in enrichsdk/contrib/lib/transforms/observability/__init__.py
get_dataset_s3(spec)
→
Use the dataset object to read the dataset
Source code in enrichsdk/contrib/lib/transforms/observability/__init__.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/observability/__init__.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
|
DataSanitizerBase(*args, **kwargs)
→
Bases: Compute
Sanitize data based on rules.
Features of transform baseclass include: * Flexible configuration * Highlevel specification of transformations * specified data source * custom defined rules
Source code in enrichsdk/contrib/lib/transforms/data_sanitizer/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/data_sanitizer/__init__.py
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/data_sanitizer/__init__.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
FeatureComputeBase(*args, **kwargs)
→
Bases: Compute
A built-in transform baseclass to handle standard feature computation and reduce the duplication of code.
This should be used in conjunction with an FeaturesetExtractor & FeatureExtractor
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
get_featureset_extractors()
→
Get all the featureset extractors (not feature extractors)
Returns: list: A list of extractors as a name, extractor combination
For example::
return [{
"name": "patient",
"extractor": <featureset extractor instance>
}]
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
get_objects()
→
Get a list of objects (typically names) to process. Could be dictionaries, lists etc. The list is not interpreted by the base class. Could be a list of identifier.
Returns: list: A list of objects (could be ids/paths/dicts etc.)
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
instantiable()
classmethod
→
process(state)
→
Core loop
Rough logic::
get featureset extractors
get objects
for each object:
for each featureset extractor X
process one object with X
collect one featureset 'row' for X
for each featureset extractor X
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
read_object(obj)
→
Read one object returned by get_objects
Args: obj (object): One item in the list of objects
Returns: object: An object like dict or list of dicts
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
store(data)
→
Store the final result
Args: data (dict): name of featureset -> data associated with it
FileBasedQueryExecutorBase(*args, **kwargs)
→
Bases: Compute
Base class for a File-based QueryExecutor transform. This is useful to run queries against backends such as backends such as mysql
Features of transform baseclass include:
* Support query engines (MySQL, Hive, Presto)
* Support templatized execution
* Support arbitrary number of queries
* Supports a generator function to generate per-interval queries
Configuration looks like::
...
"args": {
"cleanup": False,
"force": True,
"names": "all",
"start": "2020-08-01",
"end": "2020-08-03",
}
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
generator_daily(spec, specitem, query)
→
Built-in function to generate a list of dates (one for each day) between two dates.
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_executor(specitem, query, credentials)
→
Get executor for a specitem and credentials. This executor runs the query.
The executor could be specified within the query, spec, or could default to built-in one based on the credentials and dbtype within.
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
credentials (dict): Credentials for the backend
Returns:
a callable executor
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_generator(specitem, query)
→
Parameters generator. This is useful when a templatized query has to be run against the backend over many days. The output of the generator function is a list of dictionaries each of which is a key-value set for one time window (say a day)
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
Returns:
a callable generator function
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_output_handler(query, params)
→
Find a handler for the output of the query. This function should be over-ridden to compute the handler dynamically.
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_spec()
→
Get query execution specification. Override this
Returns:
specs (list): A list of dictionaries. Each dictionary specifies name, credentials, queries to run
Example::
return [ { "name": "roomdb", "cred": "roomdb", "queries": [ { "name": "select_star", "output": "%(data_root)s/shared/db/select_star/%(dt)s.tsv", "sql": "%(transform_root)s/SQL/select_star.sql", "params": { "alpha": 22 } } ] }, { "enable": False, "name": "hive", "cred": "hiveserver", "queries": [ { "name": "employees", "output": "%(data_root)s/shared/db/employee/%(dt)s.tsv", "sql": "%(transform_root)s/SQL/employees.hql", } ] } ]
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
hive_executor(specitem, credentials, query, params)
→
Built in executor for queries against a hive backend. The output is dumped to a temporary file and then an output handler is called for post-processing.
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
credentials (dict): Credentials for the backend
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
mysql_executor(specitem, credentials, query, params)
→
Built in executor for queries against a mysql backend. The output is dumped to a temporary file and then an output handler is called for post-processing.
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
credentials (dict): Credentials for the backend
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
preload_clean_args(args)
→
Check validity of the args
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
process_spec(spec)
→
Process query specification
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
validate_results(what, state)
→
validate_spec(spec)
→
Check whether specification is valid
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
FileOperationsBase(*args, **kwargs)
→
Bases: Trigger
Base class for a FileOperations transform. For now only one action is supported 'copy'. More actions will be added in future.
Example::
{
"transform": "FileOperations",
"enable": true,
"dependencies": {
....
},
"args": {
"actions": [
{
"action": "copy",
"src": "%(output)s/%(runid)s/profile.sqlite",
"dst": "%(data_root)s/shared/campaigns/profile_daily/profile.sqlite",
"backupsuffix": ".backup"
},
]
}
}
Source code in enrichsdk/contrib/lib/transforms/fileops/__init__.py
preload_clean_args(args)
→
Clean when the spec is loaded...
Source code in enrichsdk/contrib/lib/transforms/fileops/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/fileops/__init__.py
InMemoryQueryExecutorBase(*args, **kwargs)
→
Bases: AnonymizerMixin
, Compute
Base class for an InMemory QueryExecutor transform. This is useful to run queries against backends such as backends such as mysql
Features of transform baseclass include:
* Support multiple query engines (via SQLAlchemy)
* Support templatized execution
* Support arbitrary number of queries
* Supports a generator function to generate per-interval queries
Configuration looks like::
...
"args": {
"cleanup": False,
"force": True,
"targets": "all",
"start_date": "2020-08-01",
"end_date": "2020-08-03",
}
Specs
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
generic_clean(df)
→
Do a high level clean of the query result before doing a query-specific clean
get_engine(spec)
→
get_registry()
→
get_specs()
→
get_specs_from_sqls(sqldir)
→
Helper function. Load specifications from the SQLs.
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
get_sql_specs()
→
Return a list of query specifications.
Specification: A list of dictionaries. Each dict has
- name: Name of the specification
- sql: SQL template
- categories: String or a list of strings indicating specification groups
- segment: How to split the dataframe resulting from query execution. Could be none ('complete' as the default name), string (column name) or a callback that generates a { name: df } map
- paramsets_duration: each instance for one 'day' or a window of days (defined below)
- paramsets_window: each instance translates into date range for each instance of parameters.
Examples::
Simple: { "name": "txn_value", "sql": "txn_value.sql", "segment": "global_date", }
Simple:
{
"categories": ["kyc"],
"name": "kyc_txn_summary",
"sql": "kyc_txn_summary.sql",
"segment": complex_split_callbak,
"paramsets_duration": "day",
"retries": 3,
},
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
get_supported_extra_args()
→
Look at the specs to generate a list of options that can be presented to the end-ser
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
preload_clean_args(args)
→
Check validity of the args
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
update_frame(name, engine, sql, df, dependencies=[])
→
Note the lineage for each output file.
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
MetricsBase(*args, **kwargs)
→
Bases: Compute
Compute metrics as input for the anomaly/other computation
Features of transform baseclass include:
* Flexible configuration
* Highlevel specification of dimensions and metrics
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
get_dataset_generic(source)
→
Use the dataset object to read the dataset
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
get_datasets(profile, specs)
→
Load the datasets specified by the profile
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
get_db_uri(source)
→
get_handlers(profile)
→
Define various callbacks that take a dataframe, spec and compute. Specific to a single profile.
get_printable_db_uri(engine)
→
pretty print the URL
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
process_spec_default(datasets, profile, spec)
→
Handle one specification at a time..
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
NotebookExecutorBase(*args, **kwargs)
→
Bases: Compute
A built-in transform baseclass to handle standard notebook operation and reduce the duplication of code.
Features of this transform include:
* Support for custom args and environment
* Support for automatic capture and surfacing of output and err
Configuration looks like::
class MyTestNotebook(NotebookExecutorBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.name = "TestNotebook"
self.notebook = os.path.join(thisdir, "Test-Notebook.ipynb")
@classmethod
def instantiable(cls):
return True
def get_environment(self):
return {
'SECRET': credentials
}
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
get_environment()
→
get_notebook()
→
Define notebook that must be executed
Returns:
str: Path to the notebook
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
preload_clean_args(args)
→
Standard args preprocessor. Make sure that an artifacts directory is created for storing the configuration file, output notebook and stdout/err.
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
SyntheticDataGeneratorBase(*args, **kwargs)
→
Bases: Compute
Generate synthetic data given a specification
Features of transform baseclass include: * Flexible configuration * Highlevel specification of synthetic data in each column * instance: pre-defined faker-based instances * distribution: pre-defined from statistical distributions * custom: custom defined in base/derived class
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
anon_email(data, col_name, column)
→
Method to anonymize email data. Can generate emails to match or not match data in some name field. Also respects original email domain distribution if required. Input is the full dataframe, output is the relavant column being anonymized.
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
anon_numeric(data, col_name, column)
→
Method to fuzz numeric data. Various fuzzing methods can be defined here. Input is the full dataframe, output is the relavant column being fuzzed.
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
anonymize_dataset(spec, data)
→
Anonymize a dataset given a spec
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
anonymize_single_column(col_name, col_obj, data, params)
→
Takes a dataset and anonymizes the specified column
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
get_dataset_s3(spec)
→
Use the dataset object to read the dataset
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 |
|
TimeSeriesForecasterBase(*args, **kwargs)
→
Bases: Compute
Take a timeseries and project it's future values with exogenous variables. Features of transform baseclass include: * Flexible configuration * Highlevel specification of time series forecasting * specified data source or custom method to generate one * by default, forecast using facebook's prophet library or custom defined ones using other libraries
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
combined_dataset(spec, data)
→
Adds the combined dataset to the data dict
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
get_datewindow(source, spec)
→
Set the time window for observations and exogenous variables. Get both of these from args parameters if not start_date defaults to 60 days prior to end date end_date is day prior to run_date, which is usually today
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
get_handlers(spec)
→
load_source(spec)
→
Load all the sources to a 'data' dict modifies the 'data' dict.
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
postprocess_results(spec, result)
→
Postprocess the results. The method defined in the subclass
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
precheck_spec(spec)
→
Check if the spec is valid
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
process(state)
→
Run the computation and update the state 1. Load the datasets 2. Run forecasting 3. process the forecasting results 4. store the results
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
process_spec(spec, data)
→
Process the forecaster spec. generate result and chart for each forecaster
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
run_forecasting(spec, data, forecaster_name, forecaster)
→
Instantiate the forecaster and run forecasting
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
anomalies
→
AnomaliesBase(*args, **kwargs)
→
Bases: Compute
Compute anomalies given a dataframe with columns
Features of transform baseclass include:
* Flexible configuration
* Highlevel specification of columns combinations and detection strategy
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
get_dataset_s3(spec, paths)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
get_handlers(spec)
→
get_profile()
→
Read the profile json from API
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
preprocess_spec(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 |
|
process_spec_default(data, spec)
→
Handle one specification at a time..
Source code in enrichsdk/contrib/lib/transforms/anomalies/__init__.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
changepoints
→
ChangePointDetectorBase(*args, **kwargs)
→
Bases: Compute
Take a timeseries signal and identify changepoints in the signal
Features of transform baseclass include: * Flexible configuration * Highlevel specification of change point detection: * specified data source or custom method to generate one * generic change point detection method or custom defined ones
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
|
process_spec_default(spec, data)
→
Run the default change point detection
Source code in enrichsdk/contrib/lib/transforms/changepoints/__init__.py
classifier
→
ClassifierBase(*args, **kwargs)
→
Bases: Compute
Take a training dataset and one or more eval datasets Builds a classification model using the training dataset Applies the model on the eval dataset(s) and generates predictions
Features of transform baseclass include: * Flexible configuration * Highlevel specification of steps in ML classification flow: * specify multiple datasets (one for training, one or more for evaluation) * specify optional dataset prep methods * specify training model details with support for imbalanced datasets * specify evaluation strategy on one or more datasets
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
do_training(profilespec, modelspec, X, y, model, cv, metric)
→
Train a model given a dataset and a pipeline
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
|
get_classifier_pipeline(model)
→
Construct the classifier pipeline 1. resampling 2. classifier model
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
get_handlers(spec)
→
load_sources(profilespec)
→
Load all the data sources
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
make_predictions(profilespec, data, classifiers, artifacts)
→
Generate predictions for the various eval datasets
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
|
prep_data(profilespec, data, artifacts)
→
Do any data prep needed We may need to do data scaling, normalization, etc. here Any artifacts of the prep that will be needed by the prediction stage must be returned in this function
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 |
|
store_metadata(spec, results)
→
Store all the metadata for the full run
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
train_models(profilespec, data)
→
Model training
Source code in enrichsdk/contrib/lib/transforms/classifier/__init__.py
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
|
data_quality
→
DataQualityBase(*args, **kwargs)
→
Bases: Compute
Run data quality checks against a data source based on a spec
Features of transform baseclass include: * Flexible configuration * Highlevel specification of observability: * specified data source * custom defined data quality checks (same DSL as Great Expectation python package)
Source code in enrichsdk/contrib/lib/transforms/data_quality/__init__.py
get_dataset_s3(spec, paths)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/data_quality/__init__.py
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/data_quality/__init__.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
|
data_sanitizer
→
DataSanitizerBase(*args, **kwargs)
→
Bases: Compute
Sanitize data based on rules.
Features of transform baseclass include: * Flexible configuration * Highlevel specification of transformations * specified data source * custom defined rules
Source code in enrichsdk/contrib/lib/transforms/data_sanitizer/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/data_sanitizer/__init__.py
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/data_sanitizer/__init__.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
feature_compute
→
FeatureComputeBase(*args, **kwargs)
→
Bases: Compute
A built-in transform baseclass to handle standard feature computation and reduce the duplication of code.
This should be used in conjunction with an FeaturesetExtractor & FeatureExtractor
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
get_featureset_extractors()
→
Get all the featureset extractors (not feature extractors)
Returns: list: A list of extractors as a name, extractor combination
For example::
return [{
"name": "patient",
"extractor": <featureset extractor instance>
}]
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
get_objects()
→
Get a list of objects (typically names) to process. Could be dictionaries, lists etc. The list is not interpreted by the base class. Could be a list of identifier.
Returns: list: A list of objects (could be ids/paths/dicts etc.)
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
instantiable()
classmethod
→
process(state)
→
Core loop
Rough logic::
get featureset extractors
get objects
for each object:
for each featureset extractor X
process one object with X
collect one featureset 'row' for X
for each featureset extractor X
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
read_object(obj)
→
Read one object returned by get_objects
Args: obj (object): One item in the list of objects
Returns: object: An object like dict or list of dicts
Source code in enrichsdk/contrib/lib/transforms/feature_compute/__init__.py
store(data)
→
Store the final result
Args: data (dict): name of featureset -> data associated with it
filebased_query_executor
→
FileBasedQueryExecutorBase(*args, **kwargs)
→
Bases: Compute
Base class for a File-based QueryExecutor transform. This is useful to run queries against backends such as backends such as mysql
Features of transform baseclass include:
* Support query engines (MySQL, Hive, Presto)
* Support templatized execution
* Support arbitrary number of queries
* Supports a generator function to generate per-interval queries
Configuration looks like::
...
"args": {
"cleanup": False,
"force": True,
"names": "all",
"start": "2020-08-01",
"end": "2020-08-03",
}
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
generator_daily(spec, specitem, query)
→
Built-in function to generate a list of dates (one for each day) between two dates.
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_executor(specitem, query, credentials)
→
Get executor for a specitem and credentials. This executor runs the query.
The executor could be specified within the query, spec, or could default to built-in one based on the credentials and dbtype within.
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
credentials (dict): Credentials for the backend
Returns:
a callable executor
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_generator(specitem, query)
→
Parameters generator. This is useful when a templatized query has to be run against the backend over many days. The output of the generator function is a list of dictionaries each of which is a key-value set for one time window (say a day)
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
Returns:
a callable generator function
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_output_handler(query, params)
→
Find a handler for the output of the query. This function should be over-ridden to compute the handler dynamically.
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
get_spec()
→
Get query execution specification. Override this
Returns:
specs (list): A list of dictionaries. Each dictionary specifies name, credentials, queries to run
Example::
return [ { "name": "roomdb", "cred": "roomdb", "queries": [ { "name": "select_star", "output": "%(data_root)s/shared/db/select_star/%(dt)s.tsv", "sql": "%(transform_root)s/SQL/select_star.sql", "params": { "alpha": 22 } } ] }, { "enable": False, "name": "hive", "cred": "hiveserver", "queries": [ { "name": "employees", "output": "%(data_root)s/shared/db/employee/%(dt)s.tsv", "sql": "%(transform_root)s/SQL/employees.hql", } ] } ]
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
hive_executor(specitem, credentials, query, params)
→
Built in executor for queries against a hive backend. The output is dumped to a temporary file and then an output handler is called for post-processing.
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
credentials (dict): Credentials for the backend
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
mysql_executor(specitem, credentials, query, params)
→
Built in executor for queries against a mysql backend. The output is dumped to a temporary file and then an output handler is called for post-processing.
Args:
spec (dict): Specification of the query
query (dict): Particular query to execute
credentials (dict): Credentials for the backend
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
preload_clean_args(args)
→
Check validity of the args
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
process_spec(spec)
→
Process query specification
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
validate_results(what, state)
→
validate_spec(spec)
→
Check whether specification is valid
Source code in enrichsdk/contrib/lib/transforms/filebased_query_executor/__init__.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
fileops
→
File Operations ^^^^^^^^^^^^^^^
FileOperationsBase(*args, **kwargs)
→
Bases: Trigger
Base class for a FileOperations transform. For now only one action is supported 'copy'. More actions will be added in future.
Example::
{
"transform": "FileOperations",
"enable": true,
"dependencies": {
....
},
"args": {
"actions": [
{
"action": "copy",
"src": "%(output)s/%(runid)s/profile.sqlite",
"dst": "%(data_root)s/shared/campaigns/profile_daily/profile.sqlite",
"backupsuffix": ".backup"
},
]
}
}
Source code in enrichsdk/contrib/lib/transforms/fileops/__init__.py
preload_clean_args(args)
→
Clean when the spec is loaded...
Source code in enrichsdk/contrib/lib/transforms/fileops/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/fileops/__init__.py
inmemory_query_executor
→
InMemoryQueryExecutorBase(*args, **kwargs)
→
Bases: AnonymizerMixin
, Compute
Base class for an InMemory QueryExecutor transform. This is useful to run queries against backends such as backends such as mysql
Features of transform baseclass include:
* Support multiple query engines (via SQLAlchemy)
* Support templatized execution
* Support arbitrary number of queries
* Supports a generator function to generate per-interval queries
Configuration looks like::
...
"args": {
"cleanup": False,
"force": True,
"targets": "all",
"start_date": "2020-08-01",
"end_date": "2020-08-03",
}
Specs
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
generic_clean(df)
→
Do a high level clean of the query result before doing a query-specific clean
get_engine(spec)
→
get_registry()
→
get_specs()
→
get_specs_from_sqls(sqldir)
→
Helper function. Load specifications from the SQLs.
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
get_sql_specs()
→
Return a list of query specifications.
Specification: A list of dictionaries. Each dict has
- name: Name of the specification
- sql: SQL template
- categories: String or a list of strings indicating specification groups
- segment: How to split the dataframe resulting from query execution. Could be none ('complete' as the default name), string (column name) or a callback that generates a { name: df } map
- paramsets_duration: each instance for one 'day' or a window of days (defined below)
- paramsets_window: each instance translates into date range for each instance of parameters.
Examples::
Simple: { "name": "txn_value", "sql": "txn_value.sql", "segment": "global_date", }
Simple:
{
"categories": ["kyc"],
"name": "kyc_txn_summary",
"sql": "kyc_txn_summary.sql",
"segment": complex_split_callbak,
"paramsets_duration": "day",
"retries": 3,
},
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
get_supported_extra_args()
→
Look at the specs to generate a list of options that can be presented to the end-ser
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
preload_clean_args(args)
→
Check validity of the args
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
update_frame(name, engine, sql, df, dependencies=[])
→
Note the lineage for each output file.
Source code in enrichsdk/contrib/lib/transforms/inmemory_query_executor/__init__.py
metrics
→
MetricsBase(*args, **kwargs)
→
Bases: Compute
Compute metrics as input for the anomaly/other computation
Features of transform baseclass include:
* Flexible configuration
* Highlevel specification of dimensions and metrics
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
get_dataset_generic(source)
→
Use the dataset object to read the dataset
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
get_datasets(profile, specs)
→
Load the datasets specified by the profile
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
get_db_uri(source)
→
get_handlers(profile)
→
Define various callbacks that take a dataframe, spec and compute. Specific to a single profile.
get_printable_db_uri(engine)
→
pretty print the URL
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
process_spec_default(datasets, profile, spec)
→
Handle one specification at a time..
Source code in enrichsdk/contrib/lib/transforms/metrics/__init__.py
notebook_executor
→
NotebookExecutorBase(*args, **kwargs)
→
Bases: Compute
A built-in transform baseclass to handle standard notebook operation and reduce the duplication of code.
Features of this transform include:
* Support for custom args and environment
* Support for automatic capture and surfacing of output and err
Configuration looks like::
class MyTestNotebook(NotebookExecutorBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.name = "TestNotebook"
self.notebook = os.path.join(thisdir, "Test-Notebook.ipynb")
@classmethod
def instantiable(cls):
return True
def get_environment(self):
return {
'SECRET': credentials
}
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
get_environment()
→
get_notebook()
→
Define notebook that must be executed
Returns:
str: Path to the notebook
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
preload_clean_args(args)
→
Standard args preprocessor. Make sure that an artifacts directory is created for storing the configuration file, output notebook and stdout/err.
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/notebook_executor/__init__.py
observability
→
DataObserverBase(*args, **kwargs)
→
Bases: Compute
Monitor an input data source given a spec
Features of transform baseclass include: * Flexible configuration * Highlevel specification of observability: * specified data source * custom defined testing conditions for observability * custom defined output of observability results * notification of observability results on success/failure
Source code in enrichsdk/contrib/lib/transforms/observability/__init__.py
get_dataset_s3(spec)
→
Use the dataset object to read the dataset
Source code in enrichsdk/contrib/lib/transforms/observability/__init__.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/observability/__init__.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
|
synthetic_data_generator
→
SyntheticDataGeneratorBase(*args, **kwargs)
→
Bases: Compute
Generate synthetic data given a specification
Features of transform baseclass include: * Flexible configuration * Highlevel specification of synthetic data in each column * instance: pre-defined faker-based instances * distribution: pre-defined from statistical distributions * custom: custom defined in base/derived class
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
anon_email(data, col_name, column)
→
Method to anonymize email data. Can generate emails to match or not match data in some name field. Also respects original email domain distribution if required. Input is the full dataframe, output is the relavant column being anonymized.
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
anon_numeric(data, col_name, column)
→
Method to fuzz numeric data. Various fuzzing methods can be defined here. Input is the full dataframe, output is the relavant column being fuzzed.
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
anonymize_dataset(spec, data)
→
Anonymize a dataset given a spec
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
anonymize_single_column(col_name, col_obj, data, params)
→
Takes a dataset and anonymizes the specified column
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
get_dataset_s3(spec)
→
Use the dataset object to read the dataset
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
get_handlers(spec)
→
process(state)
→
Run the computation and update the state
Source code in enrichsdk/contrib/lib/transforms/synthetic_data_generator/__init__.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 |
|
timeseries_forecaster
→
TimeSeriesForecasterBase(*args, **kwargs)
→
Bases: Compute
Take a timeseries and project it's future values with exogenous variables. Features of transform baseclass include: * Flexible configuration * Highlevel specification of time series forecasting * specified data source or custom method to generate one * by default, forecast using facebook's prophet library or custom defined ones using other libraries
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
combined_dataset(spec, data)
→
Adds the combined dataset to the data dict
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
get_dataset_s3(spec, source, paths, start_date, end_date)
→
Gets all files from paths and puts them together into a single dataframe. If self.args['cache']==True, then this consolidated dataframe is cached / read from cache as applicable.
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
get_datewindow(source, spec)
→
Set the time window for observations and exogenous variables. Get both of these from args parameters if not start_date defaults to 60 days prior to end date end_date is day prior to run_date, which is usually today
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
get_handlers(spec)
→
load_source(spec)
→
Load all the sources to a 'data' dict modifies the 'data' dict.
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
postprocess_results(spec, result)
→
Postprocess the results. The method defined in the subclass
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
precheck_spec(spec)
→
Check if the spec is valid
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
process(state)
→
Run the computation and update the state 1. Load the datasets 2. Run forecasting 3. process the forecasting results 4. store the results
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
process_spec(spec, data)
→
Process the forecaster spec. generate result and chart for each forecaster
Source code in enrichsdk/contrib/lib/transforms/timeseries_forecaster/__init__.py
run_forecasting(spec, data, forecaster_name, forecaster)
→
Instantiate the forecaster and run forecasting