-
Notifications
You must be signed in to change notification settings - Fork 21
/
orca.py
1983 lines (1559 loc) · 54.4 KB
/
orca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
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
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
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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
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
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
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Orca
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.
from __future__ import print_function
import inspect
import logging
import time
import warnings
from collections import Callable, namedtuple
from contextlib import contextmanager
from functools import wraps
import pandas as pd
import tables
from zbox import toolz as tz
from . import utils
from .utils.logutil import log_start_finish
warnings.filterwarnings('ignore', category=tables.NaturalNameWarning)
logger = logging.getLogger(__name__)
_TABLES = {}
_COLUMNS = {}
_STEPS = {}
_BROADCASTS = {}
_INJECTABLES = {}
_CACHING = True
_TABLE_CACHE = {}
_COLUMN_CACHE = {}
_INJECTABLE_CACHE = {}
_MEMOIZED = {}
_CS_FOREVER = 'forever'
_CS_ITER = 'iteration'
_CS_STEP = 'step'
CacheItem = namedtuple('CacheItem', ['name', 'value', 'scope'])
def clear_all():
"""
Clear any and all stored state from Orca.
"""
_TABLES.clear()
_COLUMNS.clear()
_STEPS.clear()
_BROADCASTS.clear()
_INJECTABLES.clear()
_TABLE_CACHE.clear()
_COLUMN_CACHE.clear()
_INJECTABLE_CACHE.clear()
for m in _MEMOIZED.values():
m.value.clear_cached()
_MEMOIZED.clear()
logger.debug('pipeline state cleared')
def clear_cache(scope=None):
"""
Clear all cached data.
Parameters
----------
scope : {None, 'step', 'iteration', 'forever'}, optional
Clear cached values with a given scope.
By default all cached values are removed.
"""
if not scope:
_TABLE_CACHE.clear()
_COLUMN_CACHE.clear()
_INJECTABLE_CACHE.clear()
for m in _MEMOIZED.values():
m.value.clear_cached()
logger.debug('pipeline cache cleared')
else:
for d in (_TABLE_CACHE, _COLUMN_CACHE, _INJECTABLE_CACHE):
items = tz.valfilter(lambda x: x.scope == scope, d)
for k in items:
del d[k]
for m in tz.filter(lambda x: x.scope == scope, _MEMOIZED.values()):
m.value.clear_cached()
logger.debug('cleared cached values with scope {!r}'.format(scope))
def enable_cache():
"""
Allow caching of registered variables that explicitly have
caching enabled.
"""
global _CACHING
_CACHING = True
def disable_cache():
"""
Turn off caching across Orca, even for registered variables
that have caching enabled.
"""
global _CACHING
_CACHING = False
def cache_on():
"""
Whether caching is currently enabled or disabled.
Returns
-------
on : bool
True if caching is enabled.
"""
return _CACHING
@contextmanager
def cache_disabled():
turn_back_on = True if cache_on() else False
disable_cache()
yield
if turn_back_on:
enable_cache()
# for errors that occur during Orca runs
class OrcaError(Exception):
pass
class DataFrameWrapper(object):
"""
Wraps a DataFrame so it can provide certain columns and handle
computed columns.
Parameters
----------
name : str
Name for the table.
frame : pandas.DataFrame
copy_col : bool, optional
Whether to return copies when evaluating columns.
Attributes
----------
name : str
Table name.
copy_col : bool
Whether to return copies when evaluating columns.
local : pandas.DataFrame
The wrapped DataFrame.
"""
def __init__(self, name, frame, copy_col=True):
self.name = name
self.local = frame
self.copy_col = copy_col
@property
def columns(self):
"""
Columns in this table.
"""
return self.local_columns + list_columns_for_table(self.name)
@property
def local_columns(self):
"""
Columns that are part of the wrapped DataFrame.
"""
return list(self.local.columns)
@property
def index(self):
"""
Table index.
"""
return self.local.index
def to_frame(self, columns=None):
"""
Make a DataFrame with the given columns.
Will always return a copy of the underlying table.
Parameters
----------
columns : sequence, optional
Sequence of the column names desired in the DataFrame.
If None all columns are returned, including registered columns.
Returns
-------
frame : pandas.DataFrame
"""
extra_cols = _columns_for_table(self.name)
if columns:
local_cols = [c for c in self.local.columns
if c in columns and c not in extra_cols]
extra_cols = tz.keyfilter(lambda c: c in columns, extra_cols)
df = self.local[local_cols].copy()
else:
df = self.local.copy()
with log_start_finish(
'computing {!r} columns for table {!r}'.format(
len(extra_cols), self.name),
logger):
for name, col in extra_cols.items():
with log_start_finish(
'computing column {!r} for table {!r}'.format(
name, self.name),
logger):
df[name] = col()
return df
def update_col(self, column_name, series):
"""
Add or replace a column in the underlying DataFrame.
Parameters
----------
column_name : str
Column to add or replace.
series : pandas.Series or sequence
Column data.
"""
logger.debug('updating column {!r} in table {!r}'.format(
column_name, self.name))
self.local[column_name] = series
def __setitem__(self, key, value):
return self.update_col(key, value)
def get_column(self, column_name):
"""
Returns a column as a Series.
Parameters
----------
column_name : str
Returns
-------
column : pandas.Series
"""
with log_start_finish(
'getting single column {!r} from table {!r}'.format(
column_name, self.name),
logger):
extra_cols = _columns_for_table(self.name)
if column_name in extra_cols:
with log_start_finish(
'computing column {!r} for table {!r}'.format(
column_name, self.name),
logger):
column = extra_cols[column_name]()
else:
column = self.local[column_name]
if self.copy_col:
return column.copy()
else:
return column
def __getitem__(self, key):
return self.get_column(key)
def __getattr__(self, key):
return self.get_column(key)
def column_type(self, column_name):
"""
Report column type as one of 'local', 'series', or 'function'.
Parameters
----------
column_name : str
Returns
-------
col_type : {'local', 'series', 'function'}
'local' means that the column is part of the registered table,
'series' means the column is a registered Pandas Series,
and 'function' means the column is a registered function providing
a Pandas Series.
"""
extra_cols = list_columns_for_table(self.name)
if column_name in extra_cols:
col = _COLUMNS[(self.name, column_name)]
if isinstance(col, _SeriesWrapper):
return 'series'
elif isinstance(col, _ColumnFuncWrapper):
return 'function'
elif column_name in self.local_columns:
return 'local'
raise KeyError('column {!r} not found'.format(column_name))
def update_col_from_series(self, column_name, series):
"""
Update existing values in a column from another series.
Index values must match in both column and series.
Parameters
---------------
column_name : str
series : panas.Series
"""
logger.debug('updating column {!r} in table {!r}'.format(
column_name, self.name))
self.local.loc[series.index, column_name] = series
def __len__(self):
return len(self.local)
def clear_cached(self):
"""
Remove cached results from this table's computed columns.
"""
_TABLE_CACHE.pop(self.name, None)
for col in _columns_for_table(self.name).values():
col.clear_cached()
logger.debug('cleared cached columns for table {!r}'.format(self.name))
class TableFuncWrapper(object):
"""
Wrap a function that provides a DataFrame.
Parameters
----------
name : str
Name for the table.
func : callable
Callable that returns a DataFrame.
cache : bool, optional
Whether to cache the results of calling the wrapped function.
cache_scope : {'step', 'iteration', 'forever'}, optional
Scope for which to cache data. Default is to cache forever
(or until manually cleared). 'iteration' caches data for each
complete iteration of the pipeline, 'step' caches data for
a single step of the pipeline.
copy_col : bool, optional
Whether to return copies when evaluating columns.
Attributes
----------
name : str
Table name.
cache : bool
Whether caching is enabled for this table.
copy_col : bool
Whether to return copies when evaluating columns.
"""
def __init__(
self, name, func, cache=False, cache_scope=_CS_FOREVER,
copy_col=True):
self.name = name
self._func = func
self._argspec = inspect.getargspec(func)
self.cache = cache
self.cache_scope = cache_scope
self.copy_col = copy_col
self._columns = []
self._index = None
self._len = 0
@property
def columns(self):
"""
Columns in this table. (May contain only computed columns
if the wrapped function has not been called yet.)
"""
return self._columns + list_columns_for_table(self.name)
@property
def local_columns(self):
"""
Only the columns contained in the DataFrame returned by the
wrapped function. (No registered columns included.)
"""
if self._columns:
return self._columns
else:
self._call_func()
return self._columns
@property
def index(self):
"""
Index of the underlying table. Will be None if that index is
unknown.
"""
return self._index
def _call_func(self):
"""
Call the wrapped function and return the result wrapped by
DataFrameWrapper.
Also updates attributes like columns, index, and length.
"""
if _CACHING and self.cache and self.name in _TABLE_CACHE:
logger.debug('returning table {!r} from cache'.format(self.name))
return _TABLE_CACHE[self.name].value
with log_start_finish(
'call function to get frame for table {!r}'.format(
self.name),
logger):
kwargs = _collect_variables(names=self._argspec.args,
expressions=self._argspec.defaults)
frame = self._func(**kwargs)
self._columns = list(frame.columns)
self._index = frame.index
self._len = len(frame)
wrapped = DataFrameWrapper(self.name, frame, copy_col=self.copy_col)
if self.cache:
_TABLE_CACHE[self.name] = CacheItem(
self.name, wrapped, self.cache_scope)
return wrapped
def __call__(self):
return self._call_func()
def to_frame(self, columns=None):
"""
Make a DataFrame with the given columns.
Will always return a copy of the underlying table.
Parameters
----------
columns : sequence, optional
Sequence of the column names desired in the DataFrame.
If None all columns are returned.
Returns
-------
frame : pandas.DataFrame
"""
return self._call_func().to_frame(columns)
def get_column(self, column_name):
"""
Returns a column as a Series.
Parameters
----------
column_name : str
Returns
-------
column : pandas.Series
"""
frame = self._call_func()
return DataFrameWrapper(self.name, frame,
copy_col=self.copy_col).get_column(column_name)
def __getitem__(self, key):
return self.get_column(key)
def __getattr__(self, key):
return self.get_column(key)
def __len__(self):
return self._len
def column_type(self, column_name):
"""
Report column type as one of 'local', 'series', or 'function'.
Parameters
----------
column_name : str
Returns
-------
col_type : {'local', 'series', 'function'}
'local' means that the column is part of the registered table,
'series' means the column is a registered Pandas Series,
and 'function' means the column is a registered function providing
a Pandas Series.
"""
extra_cols = list_columns_for_table(self.name)
if column_name in extra_cols:
col = _COLUMNS[(self.name, column_name)]
if isinstance(col, _SeriesWrapper):
return 'series'
elif isinstance(col, _ColumnFuncWrapper):
return 'function'
elif column_name in self.local_columns:
return 'local'
raise KeyError('column {!r} not found'.format(column_name))
def clear_cached(self):
"""
Remove this table's cached result and that of associated columns.
"""
_TABLE_CACHE.pop(self.name, None)
for col in _columns_for_table(self.name).values():
col.clear_cached()
logger.debug(
'cleared cached result and cached columns for table {!r}'.format(
self.name))
def func_source_data(self):
"""
Return data about the wrapped function source, including file name,
line number, and source code.
Returns
-------
filename : str
lineno : int
The line number on which the function starts.
source : str
"""
return utils.func_source_data(self._func)
class _ColumnFuncWrapper(object):
"""
Wrap a function that returns a Series.
Parameters
----------
table_name : str
Table with which the column will be associated.
column_name : str
Name for the column.
func : callable
Should return a Series that has an
index matching the table to which it is being added.
cache : bool, optional
Whether to cache the result of calling the wrapped function.
cache_scope : {'step', 'iteration', 'forever'}, optional
Scope for which to cache data. Default is to cache forever
(or until manually cleared). 'iteration' caches data for each
complete iteration of the pipeline, 'step' caches data for
a single step of the pipeline.
Attributes
----------
name : str
Column name.
table_name : str
Name of table this column is associated with.
cache : bool
Whether caching is enabled for this column.
"""
def __init__(
self, table_name, column_name, func, cache=False,
cache_scope=_CS_FOREVER):
self.table_name = table_name
self.name = column_name
self._func = func
self._argspec = inspect.getargspec(func)
self.cache = cache
self.cache_scope = cache_scope
def __call__(self):
"""
Evaluate the wrapped function and return the result.
"""
if (_CACHING and
self.cache and
(self.table_name, self.name) in _COLUMN_CACHE):
logger.debug(
'returning column {!r} for table {!r} from cache'.format(
self.name, self.table_name))
return _COLUMN_CACHE[(self.table_name, self.name)].value
with log_start_finish(
('call function to provide column {!r} for table {!r}'
).format(self.name, self.table_name), logger):
kwargs = _collect_variables(names=self._argspec.args,
expressions=self._argspec.defaults)
col = self._func(**kwargs)
if self.cache:
_COLUMN_CACHE[(self.table_name, self.name)] = CacheItem(
(self.table_name, self.name), col, self.cache_scope)
return col
def clear_cached(self):
"""
Remove any cached result of this column.
"""
x = _COLUMN_CACHE.pop((self.table_name, self.name), None)
if x is not None:
logger.debug(
'cleared cached value for column {!r} in table {!r}'.format(
self.name, self.table_name))
def func_source_data(self):
"""
Return data about the wrapped function source, including file name,
line number, and source code.
Returns
-------
filename : str
lineno : int
The line number on which the function starts.
source : str
"""
return utils.func_source_data(self._func)
class _SeriesWrapper(object):
"""
Wrap a Series for the purpose of giving it the same interface as a
`_ColumnFuncWrapper`.
Parameters
----------
table_name : str
Table with which the column will be associated.
column_name : str
Name for the column.
series : pandas.Series
Series with index matching the table to which it is being added.
Attributes
----------
name : str
Column name.
table_name : str
Name of table this column is associated with.
"""
def __init__(self, table_name, column_name, series):
self.table_name = table_name
self.name = column_name
self._column = series
def __call__(self):
return self._column
def clear_cached(self):
"""
Here for compatibility with `_ColumnFuncWrapper`.
"""
pass
class _InjectableFuncWrapper(object):
"""
Wraps a function that will provide an injectable value elsewhere.
Parameters
----------
name : str
func : callable
cache : bool, optional
Whether to cache the result of calling the wrapped function.
cache_scope : {'step', 'iteration', 'forever'}, optional
Scope for which to cache data. Default is to cache forever
(or until manually cleared). 'iteration' caches data for each
complete iteration of the pipeline, 'step' caches data for
a single step of the pipeline.
Attributes
----------
name : str
Name of this injectable.
cache : bool
Whether caching is enabled for this injectable function.
"""
def __init__(self, name, func, cache=False, cache_scope=_CS_FOREVER):
self.name = name
self._func = func
self._argspec = inspect.getargspec(func)
self.cache = cache
self.cache_scope = cache_scope
def __call__(self):
if _CACHING and self.cache and self.name in _INJECTABLE_CACHE:
logger.debug(
'returning injectable {!r} from cache'.format(self.name))
return _INJECTABLE_CACHE[self.name].value
with log_start_finish(
'call function to provide injectable {!r}'.format(self.name),
logger):
kwargs = _collect_variables(names=self._argspec.args,
expressions=self._argspec.defaults)
result = self._func(**kwargs)
if self.cache:
_INJECTABLE_CACHE[self.name] = CacheItem(
self.name, result, self.cache_scope)
return result
def clear_cached(self):
"""
Clear a cached result for this injectable.
"""
x = _INJECTABLE_CACHE.pop(self.name, None)
if x:
logger.debug(
'injectable {!r} removed from cache'.format(self.name))
class _StepFuncWrapper(object):
"""
Wrap a step function for argument matching.
Parameters
----------
step_name : str
func : callable
Attributes
----------
name : str
Name of step.
"""
def __init__(self, step_name, func):
self.name = step_name
self._func = func
self._argspec = inspect.getargspec(func)
def __call__(self):
with log_start_finish('calling step {!r}'.format(self.name), logger):
kwargs = _collect_variables(names=self._argspec.args,
expressions=self._argspec.defaults)
return self._func(**kwargs)
def _tables_used(self):
"""
Tables injected into the step.
Returns
-------
tables : set of str
"""
args = list(self._argspec.args)
if self._argspec.defaults:
default_args = list(self._argspec.defaults)
else:
default_args = []
# Combine names from argument names and argument default values.
names = args[:len(args) - len(default_args)] + default_args
tables = set()
for name in names:
parent_name = name.split('.')[0]
if is_table(parent_name):
tables.add(parent_name)
return tables
def func_source_data(self):
"""
Return data about a step function's source, including file name,
line number, and source code.
Returns
-------
filename : str
lineno : int
The line number on which the function starts.
source : str
"""
return utils.func_source_data(self._func)
def is_table(name):
"""
Returns whether a given name refers to a registered table.
"""
return name in _TABLES
def list_tables():
"""
List of table names.
"""
return list(_TABLES.keys())
def list_columns():
"""
List of (table name, registered column name) pairs.
"""
return list(_COLUMNS.keys())
def list_steps():
"""
List of registered step names.
"""
return list(_STEPS.keys())
def list_injectables():
"""
List of registered injectables.
"""
return list(_INJECTABLES.keys())
def list_broadcasts():
"""
List of registered broadcasts as (cast table name, onto table name).
"""
return list(_BROADCASTS.keys())
def is_expression(name):
"""
Checks whether a given name is a simple variable name or a compound
variable expression.
Parameters
----------
name : str
Returns
-------
is_expr : bool
"""
return '.' in name
def _collect_variables(names, expressions=None):
"""
Map labels and expressions to registered variables.
Handles argument matching.
Example:
_collect_variables(names=['zones', 'zone_id'],
expressions=['parcels.zone_id'])
Would return a dict representing:
{'parcels': <DataFrameWrapper for zones>,
'zone_id': <pandas.Series for parcels.zone_id>}
Parameters
----------
names : list of str
List of registered variable names and/or labels.
If mixing names and labels, labels must come at the end.
expressions : list of str, optional
List of registered variable expressions for labels defined
at end of `names`. Length must match the number of labels.
Returns
-------
variables : dict
Keys match `names`. Values correspond to registered variables,
which may be wrappers or evaluated functions if appropriate.
"""
# Map registered variable labels to expressions.
if not expressions:
expressions = []
offset = len(names) - len(expressions)
labels_map = dict(tz.concatv(
tz.compatibility.zip(names[:offset], names[:offset]),
tz.compatibility.zip(names[offset:], expressions)))
all_variables = tz.merge(_INJECTABLES, _TABLES)
variables = {}
for label, expression in labels_map.items():
# In the future, more registered variable expressions could be
# supported. Currently supports names of registered variables
# and references to table columns.
if '.' in expression:
# Registered variable expression refers to column.
table_name, column_name = expression.split('.')
table = get_table(table_name)
variables[label] = table.get_column(column_name)
else:
thing = all_variables[expression]
if isinstance(thing, (_InjectableFuncWrapper, TableFuncWrapper)):
# Registered variable object is function.
variables[label] = thing()
else:
variables[label] = thing
return variables
def add_table(
table_name, table, cache=False, cache_scope=_CS_FOREVER,
copy_col=True):
"""
Register a table with Orca.
Parameters
----------
table_name : str
Should be globally unique to this table.
table : pandas.DataFrame or function
If a function, the function should return a DataFrame.
The function's argument names and keyword argument values
will be matched to registered variables when the function
needs to be evaluated by Orca.
cache : bool, optional
Whether to cache the results of a provided callable. Does not
apply if `table` is a DataFrame.
cache_scope : {'step', 'iteration', 'forever'}, optional
Scope for which to cache data. Default is to cache forever
(or until manually cleared). 'iteration' caches data for each
complete iteration of the pipeline, 'step' caches data for
a single step of the pipeline.
copy_col : bool, optional
Whether to return copies when evaluating columns.
Returns
-------
wrapped : `DataFrameWrapper` or `TableFuncWrapper`
"""
if isinstance(table, Callable):
table = TableFuncWrapper(table_name, table, cache=cache,
cache_scope=cache_scope, copy_col=copy_col)
else:
table = DataFrameWrapper(table_name, table, copy_col=copy_col)
# clear any cached data from a previously registered table
table.clear_cached()
logger.debug('registering table {!r}'.format(table_name))
_TABLES[table_name] = table
return table
def table(
table_name=None, cache=False, cache_scope=_CS_FOREVER, copy_col=True):
"""
Decorates functions that return DataFrames.
Decorator version of `add_table`. Table name defaults to
name of function.