Skip to content

Commit

Permalink
Fix CausalFrames for Pandas v1.0 and higher
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWilhelm committed Mar 12, 2020
1 parent fd3fd9d commit bee1da1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ package_dir =
# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD!
setup_requires = pyscaffold>=3.2a0,<3.3a0
# Add here dependencies of your project (semicolon/line-separated), e.g.
install_requires = numpy; pyarrow; pandas>=0.23; scikit-learn; requests; causalml; rpy2; pygam
install_requires = numpy; pyarrow; pandas>=1.0; scikit-learn; requests; causalml; rpy2; pygam
python_requires = >=3.6

[options.packages.find]
Expand Down
15 changes: 4 additions & 11 deletions src/justcause/data/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# Uncomment only when we require Python >= 3.7
# from __future__ import annotations

from abc import ABC
from functools import partial
from typing import List, Type

import numpy as np
Expand Down Expand Up @@ -38,7 +36,7 @@ class Col:
DATA_COLS = [Col.t, Col.y, Col.y_cf, Col.y_0, Col.y_1, Col.mu_0, Col.mu_1, Col.ite]


class CausalFrame(pd.DataFrame, ABC):
class CausalFrame(pd.DataFrame):
"""Special DataFrame for causal data
The CausalFrame ensures consistent naming of the columns in a DataFrame used
Expand All @@ -50,9 +48,7 @@ class CausalFrame(pd.DataFrame, ABC):

def __init__(self, data, *args, **kwargs):
covariates = kwargs.pop("covariates", None)
internal_op = kwargs.pop("_internal_operation", False) or isinstance(
data, BlockManager
)
internal_op = hasattr(self, "_names") or isinstance(data, BlockManager)

super().__init__(data, *args, **kwargs)

Expand All @@ -70,11 +66,8 @@ def __init__(self, data, *args, **kwargs):
self._names = dict(covariates=covariates)

@property
def _constructor(self) -> "CausalFrame":
# This is called during operations with CausalFrames
# We pass a marker to differentiate between explicit and implicit invocation
kwargs = {"_internal_operation": True, **self._names}
return partial(CausalFrame, **kwargs)
def _constructor(self) -> Type["CausalFrame"]:
return CausalFrame

@property
def _constructor_sliced(self) -> Type[pd.Series]:
Expand Down

0 comments on commit bee1da1

Please sign in to comment.