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
* indexes: Columns on which indexes should be created. Note that these are common across the frames. We check if the column is present in the frame and create the index
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
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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
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
* indexes: Columns on which indexes should be created. Note that these are common across the frames. We check if the column is present in the frame and create the index
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
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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
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.