causallib.utils.general_tools module

  1. Copyright 2019 IBM Corp.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Created on Jun 27, 2018

General (i.e. non-scientific) utils used throughout the package.

causallib.utils.general_tools.check_learner_is_fitted(learner)[source]

Return True if fitted and False otherwise

causallib.utils.general_tools.create_repr_string(o)[source]
Parameters

o (object) – any core object

Returns

repr string based on internal attributes

Return type

str

causallib.utils.general_tools.get_iterable_treatment_values(treatment_values, treatment_assignment, sort=True)[source]

Convert an optionally provided specification of unique treatment values to an iterable of the unique treatment options. Since user can provide treatment values as either an iterable or a single value, this conversion to an iterable allows a generic approach of going over all provided treatment values.

Parameters
  • treatment_values (None|Any|list[Any]) – Unique values of possible treatment values. Can be either one value (scalar) or list of values (any iterable). Can be None, if None - treatment values are inferred from treatment assignment.

  • treatment_assignment (Series) – The observed treatment assignment, used to infer a list of unique treatment values in case no treatment values are provided (None is passed to treatment_values).

  • sort (bool) – Whether to sort the treatment values

Returns

list of unique treatment values.

Return type

list[Any]