repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Crunch-io/crunch-cube | src/cr/cube/measures/index.py | Index.data | def data(cls, cube, weighted, prune):
"""Return ndarray representing table index by margin."""
return cls()._data(cube, weighted, prune) | python | def data(cls, cube, weighted, prune):
"""Return ndarray representing table index by margin."""
return cls()._data(cube, weighted, prune) | [
"def",
"data",
"(",
"cls",
",",
"cube",
",",
"weighted",
",",
"prune",
")",
":",
"return",
"cls",
"(",
")",
".",
"_data",
"(",
"cube",
",",
"weighted",
",",
"prune",
")"
] | Return ndarray representing table index by margin. | [
"Return",
"ndarray",
"representing",
"table",
"index",
"by",
"margin",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/index.py#L18-L20 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/index.py | Index._data | def _data(self, cube, weighted, prune):
"""ndarray representing table index by margin."""
result = []
for slice_ in cube.slices:
if cube.has_mr:
return self._mr_index(cube, weighted, prune)
num = slice_.margin(axis=0, weighted=weighted, prune=prune)
... | python | def _data(self, cube, weighted, prune):
"""ndarray representing table index by margin."""
result = []
for slice_ in cube.slices:
if cube.has_mr:
return self._mr_index(cube, weighted, prune)
num = slice_.margin(axis=0, weighted=weighted, prune=prune)
... | [
"def",
"_data",
"(",
"self",
",",
"cube",
",",
"weighted",
",",
"prune",
")",
":",
"result",
"=",
"[",
"]",
"for",
"slice_",
"in",
"cube",
".",
"slices",
":",
"if",
"cube",
".",
"has_mr",
":",
"return",
"self",
".",
"_mr_index",
"(",
"cube",
",",
... | ndarray representing table index by margin. | [
"ndarray",
"representing",
"table",
"index",
"by",
"margin",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/index.py#L22-L43 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/statshelpers.py | kakwani | def kakwani(values, ineq_axis, weights = None):
"""
Computes the Kakwani index
"""
from scipy.integrate import simps
if weights is None:
weights = ones(len(values))
# sign = -1
# if tax == True:
# sign = -1
# else:
# sign = 1
PLCx, PLCy = pseudo_lorenz(values, i... | python | def kakwani(values, ineq_axis, weights = None):
"""
Computes the Kakwani index
"""
from scipy.integrate import simps
if weights is None:
weights = ones(len(values))
# sign = -1
# if tax == True:
# sign = -1
# else:
# sign = 1
PLCx, PLCy = pseudo_lorenz(values, i... | [
"def",
"kakwani",
"(",
"values",
",",
"ineq_axis",
",",
"weights",
"=",
"None",
")",
":",
"from",
"scipy",
".",
"integrate",
"import",
"simps",
"if",
"weights",
"is",
"None",
":",
"weights",
"=",
"ones",
"(",
"len",
"(",
"values",
")",
")",
"PLCx",
"... | Computes the Kakwani index | [
"Computes",
"the",
"Kakwani",
"index"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/statshelpers.py#L48-L68 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/statshelpers.py | lorenz | def lorenz(values, weights = None):
"""
Computes Lorenz Curve coordinates
"""
if weights is None:
weights = ones(len(values))
df = pd.DataFrame({'v': values, 'w': weights})
df = df.sort_values(by = 'v')
x = cumsum(df['w'])
x = x / float(x[-1:])
y = cumsum(df['v'] * df['w'])
... | python | def lorenz(values, weights = None):
"""
Computes Lorenz Curve coordinates
"""
if weights is None:
weights = ones(len(values))
df = pd.DataFrame({'v': values, 'w': weights})
df = df.sort_values(by = 'v')
x = cumsum(df['w'])
x = x / float(x[-1:])
y = cumsum(df['v'] * df['w'])
... | [
"def",
"lorenz",
"(",
"values",
",",
"weights",
"=",
"None",
")",
":",
"if",
"weights",
"is",
"None",
":",
"weights",
"=",
"ones",
"(",
"len",
"(",
"values",
")",
")",
"df",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"'v'",
":",
"values",
",",
"'w'",... | Computes Lorenz Curve coordinates | [
"Computes",
"Lorenz",
"Curve",
"coordinates"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/statshelpers.py#L71-L85 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance.pvals | def pvals(cls, slice_, axis=0, weighted=True):
"""Wishart CDF values for slice columns as square ndarray.
Wishart CDF (Cumulative Distribution Function) is calculated to determine
statistical significance of slice columns, in relation to all other columns.
These values represent the ans... | python | def pvals(cls, slice_, axis=0, weighted=True):
"""Wishart CDF values for slice columns as square ndarray.
Wishart CDF (Cumulative Distribution Function) is calculated to determine
statistical significance of slice columns, in relation to all other columns.
These values represent the ans... | [
"def",
"pvals",
"(",
"cls",
",",
"slice_",
",",
"axis",
"=",
"0",
",",
"weighted",
"=",
"True",
")",
":",
"return",
"cls",
".",
"_factory",
"(",
"slice_",
",",
"axis",
",",
"weighted",
")",
".",
"pvals"
] | Wishart CDF values for slice columns as square ndarray.
Wishart CDF (Cumulative Distribution Function) is calculated to determine
statistical significance of slice columns, in relation to all other columns.
These values represent the answer to the question "How much is a particular
colu... | [
"Wishart",
"CDF",
"values",
"for",
"slice",
"columns",
"as",
"square",
"ndarray",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L31-L39 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance._chi_squared | def _chi_squared(self, proportions, margin, observed):
"""return ndarray of chi-squared measures for proportions' columns.
*proportions* (ndarray): The basis of chi-squared calcualations
*margin* (ndarray): Column margin for proportions (See `def _margin`)
*observed* (ndarray): Row marg... | python | def _chi_squared(self, proportions, margin, observed):
"""return ndarray of chi-squared measures for proportions' columns.
*proportions* (ndarray): The basis of chi-squared calcualations
*margin* (ndarray): Column margin for proportions (See `def _margin`)
*observed* (ndarray): Row marg... | [
"def",
"_chi_squared",
"(",
"self",
",",
"proportions",
",",
"margin",
",",
"observed",
")",
":",
"n",
"=",
"self",
".",
"_element_count",
"chi_squared",
"=",
"np",
".",
"zeros",
"(",
"[",
"n",
",",
"n",
"]",
")",
"for",
"i",
"in",
"xrange",
"(",
"... | return ndarray of chi-squared measures for proportions' columns.
*proportions* (ndarray): The basis of chi-squared calcualations
*margin* (ndarray): Column margin for proportions (See `def _margin`)
*observed* (ndarray): Row margin proportions (See `def _observed`) | [
"return",
"ndarray",
"of",
"chi",
"-",
"squared",
"measures",
"for",
"proportions",
"columns",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L45-L61 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance._pvals_from_chi_squared | def _pvals_from_chi_squared(self, pairwise_chisq):
"""return statistical significance for props' columns.
*pairwise_chisq* (ndarray) Matrix of chi-squared values (bases for Wishart CDF)
"""
return self._intersperse_insertion_rows_and_columns(
1.0 - WishartCDF(pairwise_chisq,... | python | def _pvals_from_chi_squared(self, pairwise_chisq):
"""return statistical significance for props' columns.
*pairwise_chisq* (ndarray) Matrix of chi-squared values (bases for Wishart CDF)
"""
return self._intersperse_insertion_rows_and_columns(
1.0 - WishartCDF(pairwise_chisq,... | [
"def",
"_pvals_from_chi_squared",
"(",
"self",
",",
"pairwise_chisq",
")",
":",
"return",
"self",
".",
"_intersperse_insertion_rows_and_columns",
"(",
"1.0",
"-",
"WishartCDF",
"(",
"pairwise_chisq",
",",
"self",
".",
"_n_min",
",",
"self",
".",
"_n_max",
")",
"... | return statistical significance for props' columns.
*pairwise_chisq* (ndarray) Matrix of chi-squared values (bases for Wishart CDF) | [
"return",
"statistical",
"significance",
"for",
"props",
"columns",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L76-L83 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance._factory | def _factory(slice_, axis, weighted):
"""return subclass for PairwiseSignificance, based on slice dimension types."""
if slice_.dim_types[0] == DT.MR_SUBVAR:
return _MrXCatPairwiseSignificance(slice_, axis, weighted)
return _CatXCatPairwiseSignificance(slice_, axis, weighted) | python | def _factory(slice_, axis, weighted):
"""return subclass for PairwiseSignificance, based on slice dimension types."""
if slice_.dim_types[0] == DT.MR_SUBVAR:
return _MrXCatPairwiseSignificance(slice_, axis, weighted)
return _CatXCatPairwiseSignificance(slice_, axis, weighted) | [
"def",
"_factory",
"(",
"slice_",
",",
"axis",
",",
"weighted",
")",
":",
"if",
"slice_",
".",
"dim_types",
"[",
"0",
"]",
"==",
"DT",
".",
"MR_SUBVAR",
":",
"return",
"_MrXCatPairwiseSignificance",
"(",
"slice_",
",",
"axis",
",",
"weighted",
")",
"retu... | return subclass for PairwiseSignificance, based on slice dimension types. | [
"return",
"subclass",
"for",
"PairwiseSignificance",
"based",
"on",
"slice",
"dimension",
"types",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L86-L90 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance._intersperse_insertion_rows_and_columns | def _intersperse_insertion_rows_and_columns(self, pairwise_pvals):
"""Return pvals matrix with inserted NaN rows and columns, as numpy.ndarray.
Each insertion (a header or a subtotal) creates an offset in the calculated
pvals. These need to be taken into account when converting each pval to a
... | python | def _intersperse_insertion_rows_and_columns(self, pairwise_pvals):
"""Return pvals matrix with inserted NaN rows and columns, as numpy.ndarray.
Each insertion (a header or a subtotal) creates an offset in the calculated
pvals. These need to be taken into account when converting each pval to a
... | [
"def",
"_intersperse_insertion_rows_and_columns",
"(",
"self",
",",
"pairwise_pvals",
")",
":",
"for",
"i",
"in",
"self",
".",
"_insertion_indices",
":",
"pairwise_pvals",
"=",
"np",
".",
"insert",
"(",
"pairwise_pvals",
",",
"i",
",",
"np",
".",
"nan",
",",
... | Return pvals matrix with inserted NaN rows and columns, as numpy.ndarray.
Each insertion (a header or a subtotal) creates an offset in the calculated
pvals. These need to be taken into account when converting each pval to a
corresponding column letter. For this reason, we need to insert an all-... | [
"Return",
"pvals",
"matrix",
"with",
"inserted",
"NaN",
"rows",
"and",
"columns",
"as",
"numpy",
".",
"ndarray",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L97-L109 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance._opposite_axis_margin | def _opposite_axis_margin(self):
"""ndarray representing margin along the axis opposite of self._axis
In the process of calculating p-values for the column significance testing we
need both the margin along the primary axis and the percentage margin along
the opposite axis.
"""
... | python | def _opposite_axis_margin(self):
"""ndarray representing margin along the axis opposite of self._axis
In the process of calculating p-values for the column significance testing we
need both the margin along the primary axis and the percentage margin along
the opposite axis.
"""
... | [
"def",
"_opposite_axis_margin",
"(",
"self",
")",
":",
"off_axis",
"=",
"1",
"-",
"self",
".",
"_axis",
"return",
"self",
".",
"_slice",
".",
"margin",
"(",
"axis",
"=",
"off_axis",
",",
"include_mr_cat",
"=",
"self",
".",
"_include_mr_cat",
")"
] | ndarray representing margin along the axis opposite of self._axis
In the process of calculating p-values for the column significance testing we
need both the margin along the primary axis and the percentage margin along
the opposite axis. | [
"ndarray",
"representing",
"margin",
"along",
"the",
"axis",
"opposite",
"of",
"self",
".",
"_axis"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L132-L140 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/wishart_pairwise_significance.py | WishartPairwiseSignificance._proportions | def _proportions(self):
"""ndarray representing slice proportions along correct axis."""
return self._slice.proportions(
axis=self._axis, include_mr_cat=self._include_mr_cat
) | python | def _proportions(self):
"""ndarray representing slice proportions along correct axis."""
return self._slice.proportions(
axis=self._axis, include_mr_cat=self._include_mr_cat
) | [
"def",
"_proportions",
"(",
"self",
")",
":",
"return",
"self",
".",
"_slice",
".",
"proportions",
"(",
"axis",
"=",
"self",
".",
"_axis",
",",
"include_mr_cat",
"=",
"self",
".",
"_include_mr_cat",
")"
] | ndarray representing slice proportions along correct axis. | [
"ndarray",
"representing",
"slice",
"proportions",
"along",
"correct",
"axis",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/wishart_pairwise_significance.py#L143-L147 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/calmar.py | build_dummies_dict | def build_dummies_dict(data):
"""
Return a dict with unique values as keys and vectors as values
"""
unique_val_list = unique(data)
output = {}
for val in unique_val_list:
output[val] = (data == val)
return output | python | def build_dummies_dict(data):
"""
Return a dict with unique values as keys and vectors as values
"""
unique_val_list = unique(data)
output = {}
for val in unique_val_list:
output[val] = (data == val)
return output | [
"def",
"build_dummies_dict",
"(",
"data",
")",
":",
"unique_val_list",
"=",
"unique",
"(",
"data",
")",
"output",
"=",
"{",
"}",
"for",
"val",
"in",
"unique_val_list",
":",
"output",
"[",
"val",
"]",
"=",
"(",
"data",
"==",
"val",
")",
"return",
"outpu... | Return a dict with unique values as keys and vectors as values | [
"Return",
"a",
"dict",
"with",
"unique",
"values",
"as",
"keys",
"and",
"vectors",
"as",
"values"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/calmar.py#L44-L52 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.ca_main_axis | def ca_main_axis(self):
"""For univariate CA, the main axis is the categorical axis"""
try:
ca_ind = self.dim_types.index(DT.CA_SUBVAR)
return 1 - ca_ind
except ValueError:
return None | python | def ca_main_axis(self):
"""For univariate CA, the main axis is the categorical axis"""
try:
ca_ind = self.dim_types.index(DT.CA_SUBVAR)
return 1 - ca_ind
except ValueError:
return None | [
"def",
"ca_main_axis",
"(",
"self",
")",
":",
"try",
":",
"ca_ind",
"=",
"self",
".",
"dim_types",
".",
"index",
"(",
"DT",
".",
"CA_SUBVAR",
")",
"return",
"1",
"-",
"ca_ind",
"except",
"ValueError",
":",
"return",
"None"
] | For univariate CA, the main axis is the categorical axis | [
"For",
"univariate",
"CA",
"the",
"main",
"axis",
"is",
"the",
"categorical",
"axis"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L166-L172 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.can_compare_pairwise | def can_compare_pairwise(self):
"""Return bool indicating if slice can compute pairwise comparisons.
Currently, only the CAT x CAT slice can compute pairwise comparisons. This also
includes the categorical array categories dimnension (CA_CAT).
"""
if self.ndim != 2:
... | python | def can_compare_pairwise(self):
"""Return bool indicating if slice can compute pairwise comparisons.
Currently, only the CAT x CAT slice can compute pairwise comparisons. This also
includes the categorical array categories dimnension (CA_CAT).
"""
if self.ndim != 2:
... | [
"def",
"can_compare_pairwise",
"(",
"self",
")",
":",
"if",
"self",
".",
"ndim",
"!=",
"2",
":",
"return",
"False",
"return",
"all",
"(",
"dt",
"in",
"DT",
".",
"ALLOWED_PAIRWISE_TYPES",
"for",
"dt",
"in",
"self",
".",
"dim_types",
")"
] | Return bool indicating if slice can compute pairwise comparisons.
Currently, only the CAT x CAT slice can compute pairwise comparisons. This also
includes the categorical array categories dimnension (CA_CAT). | [
"Return",
"bool",
"indicating",
"if",
"slice",
"can",
"compute",
"pairwise",
"comparisons",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L180-L189 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.get_shape | def get_shape(self, prune=False, hs_dims=None):
"""Tuple of array dimensions' lengths.
It returns a tuple of ints, each representing the length of a cube
dimension, in the order those dimensions appear in the cube.
Pruning is supported. Dimensions that get reduced to a single element
... | python | def get_shape(self, prune=False, hs_dims=None):
"""Tuple of array dimensions' lengths.
It returns a tuple of ints, each representing the length of a cube
dimension, in the order those dimensions appear in the cube.
Pruning is supported. Dimensions that get reduced to a single element
... | [
"def",
"get_shape",
"(",
"self",
",",
"prune",
"=",
"False",
",",
"hs_dims",
"=",
"None",
")",
":",
"if",
"not",
"prune",
":",
"return",
"self",
".",
"as_array",
"(",
"include_transforms_for_dims",
"=",
"hs_dims",
")",
".",
"shape",
"shape",
"=",
"compre... | Tuple of array dimensions' lengths.
It returns a tuple of ints, each representing the length of a cube
dimension, in the order those dimensions appear in the cube.
Pruning is supported. Dimensions that get reduced to a single element
(e.g. due to pruning) are removed from the returning ... | [
"Tuple",
"of",
"array",
"dimensions",
"lengths",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L197-L221 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.index_table | def index_table(self, axis=None, baseline=None, prune=False):
"""Return index percentages for a given axis and baseline.
The index values represent the difference of the percentages to the
corresponding baseline values. The baseline values are the univariate
percentages of the correspon... | python | def index_table(self, axis=None, baseline=None, prune=False):
"""Return index percentages for a given axis and baseline.
The index values represent the difference of the percentages to the
corresponding baseline values. The baseline values are the univariate
percentages of the correspon... | [
"def",
"index_table",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"baseline",
"=",
"None",
",",
"prune",
"=",
"False",
")",
":",
"proportions",
"=",
"self",
".",
"proportions",
"(",
"axis",
"=",
"axis",
")",
"baseline",
"=",
"(",
"baseline",
"if",
"b... | Return index percentages for a given axis and baseline.
The index values represent the difference of the percentages to the
corresponding baseline values. The baseline values are the univariate
percentages of the corresponding variable. | [
"Return",
"index",
"percentages",
"for",
"a",
"given",
"axis",
"and",
"baseline",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L243-L265 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.labels | def labels(self, hs_dims=None, prune=False):
"""Get labels for the cube slice, and perform pruning by slice."""
if self.ca_as_0th:
labels = self._cube.labels(include_transforms_for_dims=hs_dims)[1:]
else:
labels = self._cube.labels(include_transforms_for_dims=hs_dims)[-2:... | python | def labels(self, hs_dims=None, prune=False):
"""Get labels for the cube slice, and perform pruning by slice."""
if self.ca_as_0th:
labels = self._cube.labels(include_transforms_for_dims=hs_dims)[1:]
else:
labels = self._cube.labels(include_transforms_for_dims=hs_dims)[-2:... | [
"def",
"labels",
"(",
"self",
",",
"hs_dims",
"=",
"None",
",",
"prune",
"=",
"False",
")",
":",
"if",
"self",
".",
"ca_as_0th",
":",
"labels",
"=",
"self",
".",
"_cube",
".",
"labels",
"(",
"include_transforms_for_dims",
"=",
"hs_dims",
")",
"[",
"1",... | Get labels for the cube slice, and perform pruning by slice. | [
"Get",
"labels",
"for",
"the",
"cube",
"slice",
"and",
"perform",
"pruning",
"by",
"slice",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L277-L296 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.margin | def margin(
self,
axis=None,
weighted=True,
include_missing=False,
include_transforms_for_dims=None,
prune=False,
include_mr_cat=False,
):
"""Return ndarray representing slice margin across selected axis.
A margin (or basis) can be calculated ... | python | def margin(
self,
axis=None,
weighted=True,
include_missing=False,
include_transforms_for_dims=None,
prune=False,
include_mr_cat=False,
):
"""Return ndarray representing slice margin across selected axis.
A margin (or basis) can be calculated ... | [
"def",
"margin",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"weighted",
"=",
"True",
",",
"include_missing",
"=",
"False",
",",
"include_transforms_for_dims",
"=",
"None",
",",
"prune",
"=",
"False",
",",
"include_mr_cat",
"=",
"False",
",",
")",
":",
"... | Return ndarray representing slice margin across selected axis.
A margin (or basis) can be calculated for a contingency table, provided
that the dimensions of the desired directions are marginable. The
dimensions are marginable if they represent mutualy exclusive data,
such as true categ... | [
"Return",
"ndarray",
"representing",
"slice",
"margin",
"across",
"selected",
"axis",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L298-L346 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.min_base_size_mask | def min_base_size_mask(self, size, hs_dims=None, prune=False):
"""Returns MinBaseSizeMask object with correct row, col and table masks.
The returned object stores the necessary information about the base size, as
well as about the base values. It can create corresponding masks in teh row,
... | python | def min_base_size_mask(self, size, hs_dims=None, prune=False):
"""Returns MinBaseSizeMask object with correct row, col and table masks.
The returned object stores the necessary information about the base size, as
well as about the base values. It can create corresponding masks in teh row,
... | [
"def",
"min_base_size_mask",
"(",
"self",
",",
"size",
",",
"hs_dims",
"=",
"None",
",",
"prune",
"=",
"False",
")",
":",
"return",
"MinBaseSizeMask",
"(",
"self",
",",
"size",
",",
"hs_dims",
"=",
"hs_dims",
",",
"prune",
"=",
"prune",
")"
] | Returns MinBaseSizeMask object with correct row, col and table masks.
The returned object stores the necessary information about the base size, as
well as about the base values. It can create corresponding masks in teh row,
column, and table directions, based on the corresponding base values
... | [
"Returns",
"MinBaseSizeMask",
"object",
"with",
"correct",
"row",
"col",
"and",
"table",
"masks",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L348-L362 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.mr_dim_ind | def mr_dim_ind(self):
"""Get the correct index of the MR dimension in the cube slice."""
mr_dim_ind = self._cube.mr_dim_ind
if self._cube.ndim == 3:
if isinstance(mr_dim_ind, int):
if mr_dim_ind == 0:
# If only the 0th dimension of a 3D is an MR, t... | python | def mr_dim_ind(self):
"""Get the correct index of the MR dimension in the cube slice."""
mr_dim_ind = self._cube.mr_dim_ind
if self._cube.ndim == 3:
if isinstance(mr_dim_ind, int):
if mr_dim_ind == 0:
# If only the 0th dimension of a 3D is an MR, t... | [
"def",
"mr_dim_ind",
"(",
"self",
")",
":",
"mr_dim_ind",
"=",
"self",
".",
"_cube",
".",
"mr_dim_ind",
"if",
"self",
".",
"_cube",
".",
"ndim",
"==",
"3",
":",
"if",
"isinstance",
"(",
"mr_dim_ind",
",",
"int",
")",
":",
"if",
"mr_dim_ind",
"==",
"0... | Get the correct index of the MR dimension in the cube slice. | [
"Get",
"the",
"correct",
"index",
"of",
"the",
"MR",
"dimension",
"in",
"the",
"cube",
"slice",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L365-L387 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.scale_means | def scale_means(self, hs_dims=None, prune=False):
"""Return list of column and row scaled means for this slice.
If a row/col doesn't have numerical values, return None for the
corresponding dimension. If a slice only has 1D, return only the column
scaled mean (as numpy array). If both r... | python | def scale_means(self, hs_dims=None, prune=False):
"""Return list of column and row scaled means for this slice.
If a row/col doesn't have numerical values, return None for the
corresponding dimension. If a slice only has 1D, return only the column
scaled mean (as numpy array). If both r... | [
"def",
"scale_means",
"(",
"self",
",",
"hs_dims",
"=",
"None",
",",
"prune",
"=",
"False",
")",
":",
"scale_means",
"=",
"self",
".",
"_cube",
".",
"scale_means",
"(",
"hs_dims",
",",
"prune",
")",
"if",
"self",
".",
"ca_as_0th",
":",
"scale_means",
"... | Return list of column and row scaled means for this slice.
If a row/col doesn't have numerical values, return None for the
corresponding dimension. If a slice only has 1D, return only the column
scaled mean (as numpy array). If both row and col scaled means are
present, return them as t... | [
"Return",
"list",
"of",
"column",
"and",
"row",
"scaled",
"means",
"for",
"this",
"slice",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L399-L419 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.table_name | def table_name(self):
"""Get slice name.
In case of 2D return cube name. In case of 3D, return the combination
of the cube name with the label of the corresponding slice
(nth label of the 0th dimension).
"""
if self._cube.ndim < 3 and not self.ca_as_0th:
retu... | python | def table_name(self):
"""Get slice name.
In case of 2D return cube name. In case of 3D, return the combination
of the cube name with the label of the corresponding slice
(nth label of the 0th dimension).
"""
if self._cube.ndim < 3 and not self.ca_as_0th:
retu... | [
"def",
"table_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cube",
".",
"ndim",
"<",
"3",
"and",
"not",
"self",
".",
"ca_as_0th",
":",
"return",
"None",
"title",
"=",
"self",
".",
"_cube",
".",
"name",
"table_name",
"=",
"self",
".",
"_cube",
... | Get slice name.
In case of 2D return cube name. In case of 3D, return the combination
of the cube name with the label of the corresponding slice
(nth label of the 0th dimension). | [
"Get",
"slice",
"name",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L448-L460 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.wishart_pairwise_pvals | def wishart_pairwise_pvals(self, axis=0):
"""Return square symmetric matrix of pairwise column-comparison p-values.
Square, symmetric matrix along *axis* of pairwise p-values for the
null hypothesis that col[i] = col[j] for each pair of columns.
*axis* (int): axis along which to perfor... | python | def wishart_pairwise_pvals(self, axis=0):
"""Return square symmetric matrix of pairwise column-comparison p-values.
Square, symmetric matrix along *axis* of pairwise p-values for the
null hypothesis that col[i] = col[j] for each pair of columns.
*axis* (int): axis along which to perfor... | [
"def",
"wishart_pairwise_pvals",
"(",
"self",
",",
"axis",
"=",
"0",
")",
":",
"if",
"axis",
"!=",
"0",
":",
"raise",
"NotImplementedError",
"(",
"\"Pairwise comparison only implemented for colums\"",
")",
"return",
"WishartPairwiseSignificance",
".",
"pvals",
"(",
... | Return square symmetric matrix of pairwise column-comparison p-values.
Square, symmetric matrix along *axis* of pairwise p-values for the
null hypothesis that col[i] = col[j] for each pair of columns.
*axis* (int): axis along which to perform comparison. Only columns (0)
are implemente... | [
"Return",
"square",
"symmetric",
"matrix",
"of",
"pairwise",
"column",
"-",
"comparison",
"p",
"-",
"values",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L462-L473 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.pvals | def pvals(self, weighted=True, prune=False, hs_dims=None):
"""Return 2D ndarray with calculated P values
This function calculates statistically significant cells for
categorical contingency tables under the null hypothesis that the
row and column variables are independent (uncorrelated)... | python | def pvals(self, weighted=True, prune=False, hs_dims=None):
"""Return 2D ndarray with calculated P values
This function calculates statistically significant cells for
categorical contingency tables under the null hypothesis that the
row and column variables are independent (uncorrelated)... | [
"def",
"pvals",
"(",
"self",
",",
"weighted",
"=",
"True",
",",
"prune",
"=",
"False",
",",
"hs_dims",
"=",
"None",
")",
":",
"stats",
"=",
"self",
".",
"zscore",
"(",
"weighted",
"=",
"weighted",
",",
"prune",
"=",
"prune",
",",
"hs_dims",
"=",
"h... | Return 2D ndarray with calculated P values
This function calculates statistically significant cells for
categorical contingency tables under the null hypothesis that the
row and column variables are independent (uncorrelated).
The values are calculated for 2D tables only.
:para... | [
"Return",
"2D",
"ndarray",
"with",
"calculated",
"P",
"values"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L501-L518 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice.pairwise_indices | def pairwise_indices(self, alpha=0.05, only_larger=True, hs_dims=None):
"""Indices of columns where p < alpha for column-comparison t-tests
Returns an array of tuples of columns that are significant at p<alpha,
from a series of pairwise t-tests.
Argument both_pairs returns indices stri... | python | def pairwise_indices(self, alpha=0.05, only_larger=True, hs_dims=None):
"""Indices of columns where p < alpha for column-comparison t-tests
Returns an array of tuples of columns that are significant at p<alpha,
from a series of pairwise t-tests.
Argument both_pairs returns indices stri... | [
"def",
"pairwise_indices",
"(",
"self",
",",
"alpha",
"=",
"0.05",
",",
"only_larger",
"=",
"True",
",",
"hs_dims",
"=",
"None",
")",
":",
"return",
"PairwiseSignificance",
"(",
"self",
",",
"alpha",
"=",
"alpha",
",",
"only_larger",
"=",
"only_larger",
",... | Indices of columns where p < alpha for column-comparison t-tests
Returns an array of tuples of columns that are significant at p<alpha,
from a series of pairwise t-tests.
Argument both_pairs returns indices striclty on the test statistic. If
False, however, only the index of values *si... | [
"Indices",
"of",
"columns",
"where",
"p",
"<",
"alpha",
"for",
"column",
"-",
"comparison",
"t",
"-",
"tests"
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L552-L564 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice._array_type_std_res | def _array_type_std_res(self, counts, total, colsum, rowsum):
"""Return ndarray containing standard residuals for array values.
The shape of the return value is the same as that of *counts*.
Array variables require special processing because of the
underlying math. Essentially, it boils... | python | def _array_type_std_res(self, counts, total, colsum, rowsum):
"""Return ndarray containing standard residuals for array values.
The shape of the return value is the same as that of *counts*.
Array variables require special processing because of the
underlying math. Essentially, it boils... | [
"def",
"_array_type_std_res",
"(",
"self",
",",
"counts",
",",
"total",
",",
"colsum",
",",
"rowsum",
")",
":",
"if",
"self",
".",
"mr_dim_ind",
"==",
"0",
":",
"total",
"=",
"total",
"[",
":",
",",
"np",
".",
"newaxis",
"]",
"rowsum",
"=",
"rowsum",... | Return ndarray containing standard residuals for array values.
The shape of the return value is the same as that of *counts*.
Array variables require special processing because of the
underlying math. Essentially, it boils down to the fact that the
variable dimensions are mutually indep... | [
"Return",
"ndarray",
"containing",
"standard",
"residuals",
"for",
"array",
"values",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L588-L609 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice._calculate_std_res | def _calculate_std_res(self, counts, total, colsum, rowsum):
"""Return ndarray containing standard residuals.
The shape of the return value is the same as that of *counts*.
"""
if set(self.dim_types) & DT.ARRAY_TYPES: # ---has-mr-or-ca---
return self._array_type_std_res(cou... | python | def _calculate_std_res(self, counts, total, colsum, rowsum):
"""Return ndarray containing standard residuals.
The shape of the return value is the same as that of *counts*.
"""
if set(self.dim_types) & DT.ARRAY_TYPES: # ---has-mr-or-ca---
return self._array_type_std_res(cou... | [
"def",
"_calculate_std_res",
"(",
"self",
",",
"counts",
",",
"total",
",",
"colsum",
",",
"rowsum",
")",
":",
"if",
"set",
"(",
"self",
".",
"dim_types",
")",
"&",
"DT",
".",
"ARRAY_TYPES",
":",
"return",
"self",
".",
"_array_type_std_res",
"(",
"counts... | Return ndarray containing standard residuals.
The shape of the return value is the same as that of *counts*. | [
"Return",
"ndarray",
"containing",
"standard",
"residuals",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L611-L618 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice._calculate_correct_axis_for_cube | def _calculate_correct_axis_for_cube(self, axis):
"""Return correct axis for cube, based on ndim.
If cube has 3 dimensions, increase axis by 1. This will translate the
default 0 (cols direction) and 1 (rows direction) to actual 1
(cols direction) and 2 (rows direction). This is needed b... | python | def _calculate_correct_axis_for_cube(self, axis):
"""Return correct axis for cube, based on ndim.
If cube has 3 dimensions, increase axis by 1. This will translate the
default 0 (cols direction) and 1 (rows direction) to actual 1
(cols direction) and 2 (rows direction). This is needed b... | [
"def",
"_calculate_correct_axis_for_cube",
"(",
"self",
",",
"axis",
")",
":",
"if",
"self",
".",
"_cube",
".",
"ndim",
"<",
"3",
":",
"if",
"self",
".",
"ca_as_0th",
"and",
"axis",
"is",
"None",
":",
"return",
"1",
"return",
"axis",
"if",
"isinstance",
... | Return correct axis for cube, based on ndim.
If cube has 3 dimensions, increase axis by 1. This will translate the
default 0 (cols direction) and 1 (rows direction) to actual 1
(cols direction) and 2 (rows direction). This is needed because the
0th dimension of the 3D cube is only used ... | [
"Return",
"correct",
"axis",
"for",
"cube",
"based",
"on",
"ndim",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L620-L659 | train |
Crunch-io/crunch-cube | src/cr/cube/cube_slice.py | CubeSlice._scalar_type_std_res | def _scalar_type_std_res(self, counts, total, colsum, rowsum):
"""Return ndarray containing standard residuals for category values.
The shape of the return value is the same as that of *counts*.
"""
expected_counts = expected_freq(counts)
residuals = counts - expected_counts
... | python | def _scalar_type_std_res(self, counts, total, colsum, rowsum):
"""Return ndarray containing standard residuals for category values.
The shape of the return value is the same as that of *counts*.
"""
expected_counts = expected_freq(counts)
residuals = counts - expected_counts
... | [
"def",
"_scalar_type_std_res",
"(",
"self",
",",
"counts",
",",
"total",
",",
"colsum",
",",
"rowsum",
")",
":",
"expected_counts",
"=",
"expected_freq",
"(",
"counts",
")",
"residuals",
"=",
"counts",
"-",
"expected_counts",
"variance",
"=",
"(",
"np",
".",... | Return ndarray containing standard residuals for category values.
The shape of the return value is the same as that of *counts*. | [
"Return",
"ndarray",
"containing",
"standard",
"residuals",
"for",
"category",
"values",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/cube_slice.py#L709-L721 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/scale_means.py | ScaleMeans.data | def data(self):
"""list of mean numeric values of categorical responses."""
means = []
table = self._slice.as_array()
products = self._inner_prods(table, self.values)
for axis, product in enumerate(products):
if product is None:
means.append(product)
... | python | def data(self):
"""list of mean numeric values of categorical responses."""
means = []
table = self._slice.as_array()
products = self._inner_prods(table, self.values)
for axis, product in enumerate(products):
if product is None:
means.append(product)
... | [
"def",
"data",
"(",
"self",
")",
":",
"means",
"=",
"[",
"]",
"table",
"=",
"self",
".",
"_slice",
".",
"as_array",
"(",
")",
"products",
"=",
"self",
".",
"_inner_prods",
"(",
"table",
",",
"self",
".",
"values",
")",
"for",
"axis",
",",
"product"... | list of mean numeric values of categorical responses. | [
"list",
"of",
"mean",
"numeric",
"values",
"of",
"categorical",
"responses",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/scale_means.py#L33-L52 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/scale_means.py | ScaleMeans.margin | def margin(self, axis):
"""Return marginal value of the current slice scaled means.
This value is the the same what you would get from a single variable
(constituting a 2D cube/slice), when the "non-missing" filter of the
opposite variable would be applied. This behavior is consistent w... | python | def margin(self, axis):
"""Return marginal value of the current slice scaled means.
This value is the the same what you would get from a single variable
(constituting a 2D cube/slice), when the "non-missing" filter of the
opposite variable would be applied. This behavior is consistent w... | [
"def",
"margin",
"(",
"self",
",",
"axis",
")",
":",
"if",
"self",
".",
"_slice",
".",
"ndim",
"<",
"2",
":",
"msg",
"=",
"(",
"\"Scale Means marginal cannot be calculated on 1D cubes, as\"",
"\"the scale means already get reduced to a scalar value.\"",
")",
"raise",
... | Return marginal value of the current slice scaled means.
This value is the the same what you would get from a single variable
(constituting a 2D cube/slice), when the "non-missing" filter of the
opposite variable would be applied. This behavior is consistent with
what is visible in the ... | [
"Return",
"marginal",
"value",
"of",
"the",
"current",
"slice",
"scaled",
"means",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/scale_means.py#L54-L83 | train |
Crunch-io/crunch-cube | src/cr/cube/measures/scale_means.py | ScaleMeans.values | def values(self):
"""list of ndarray value-ids for each dimension in slice.
The values for each dimension appear as an ndarray. None appears
instead of the array for each dimension having only NaN values.
"""
return [
(
np.array(dim.numeric_values)
... | python | def values(self):
"""list of ndarray value-ids for each dimension in slice.
The values for each dimension appear as an ndarray. None appears
instead of the array for each dimension having only NaN values.
"""
return [
(
np.array(dim.numeric_values)
... | [
"def",
"values",
"(",
"self",
")",
":",
"return",
"[",
"(",
"np",
".",
"array",
"(",
"dim",
".",
"numeric_values",
")",
"if",
"(",
"dim",
".",
"numeric_values",
"and",
"any",
"(",
"~",
"np",
".",
"isnan",
"(",
"dim",
".",
"numeric_values",
")",
")"... | list of ndarray value-ids for each dimension in slice.
The values for each dimension appear as an ndarray. None appears
instead of the array for each dimension having only NaN values. | [
"list",
"of",
"ndarray",
"value",
"-",
"ids",
"for",
"each",
"dimension",
"in",
"slice",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/measures/scale_means.py#L112-L125 | train |
Crunch-io/crunch-cube | src/cr/cube/util.py | compress_pruned | def compress_pruned(table):
"""Compress table based on pruning mask.
Only the rows/cols in which all of the elements are masked need to be
pruned.
"""
if not isinstance(table, np.ma.core.MaskedArray):
return table
if table.ndim == 0:
return table.data
if table.ndim == 1:
... | python | def compress_pruned(table):
"""Compress table based on pruning mask.
Only the rows/cols in which all of the elements are masked need to be
pruned.
"""
if not isinstance(table, np.ma.core.MaskedArray):
return table
if table.ndim == 0:
return table.data
if table.ndim == 1:
... | [
"def",
"compress_pruned",
"(",
"table",
")",
":",
"if",
"not",
"isinstance",
"(",
"table",
",",
"np",
".",
"ma",
".",
"core",
".",
"MaskedArray",
")",
":",
"return",
"table",
"if",
"table",
".",
"ndim",
"==",
"0",
":",
"return",
"table",
".",
"data",... | Compress table based on pruning mask.
Only the rows/cols in which all of the elements are masked need to be
pruned. | [
"Compress",
"table",
"based",
"on",
"pruning",
"mask",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/util.py#L16-L36 | train |
Crunch-io/crunch-cube | src/cr/cube/util.py | intersperse_hs_in_std_res | def intersperse_hs_in_std_res(slice_, hs_dims, res):
"""Perform the insertions of place-holding rows and cols for insertions."""
for dim, inds in enumerate(slice_.inserted_hs_indices()):
if dim not in hs_dims:
continue
for i in inds:
res = np.insert(res, i, np.nan, axis=(... | python | def intersperse_hs_in_std_res(slice_, hs_dims, res):
"""Perform the insertions of place-holding rows and cols for insertions."""
for dim, inds in enumerate(slice_.inserted_hs_indices()):
if dim not in hs_dims:
continue
for i in inds:
res = np.insert(res, i, np.nan, axis=(... | [
"def",
"intersperse_hs_in_std_res",
"(",
"slice_",
",",
"hs_dims",
",",
"res",
")",
":",
"for",
"dim",
",",
"inds",
"in",
"enumerate",
"(",
"slice_",
".",
"inserted_hs_indices",
"(",
")",
")",
":",
"if",
"dim",
"not",
"in",
"hs_dims",
":",
"continue",
"f... | Perform the insertions of place-holding rows and cols for insertions. | [
"Perform",
"the",
"insertions",
"of",
"place",
"-",
"holding",
"rows",
"and",
"cols",
"for",
"insertions",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/util.py#L39-L46 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/utils.py | inflate_parameter_leaf | def inflate_parameter_leaf(sub_parameter, base_year, inflator, unit_type = 'unit'):
"""
Inflate a Parameter leaf according to unit type
Basic unit type are supposed by default
Other admissible unit types are threshold_unit and rate_unit
"""
if isinstance(sub_parameter, Scale):
if unit_... | python | def inflate_parameter_leaf(sub_parameter, base_year, inflator, unit_type = 'unit'):
"""
Inflate a Parameter leaf according to unit type
Basic unit type are supposed by default
Other admissible unit types are threshold_unit and rate_unit
"""
if isinstance(sub_parameter, Scale):
if unit_... | [
"def",
"inflate_parameter_leaf",
"(",
"sub_parameter",
",",
"base_year",
",",
"inflator",
",",
"unit_type",
"=",
"'unit'",
")",
":",
"if",
"isinstance",
"(",
"sub_parameter",
",",
"Scale",
")",
":",
"if",
"unit_type",
"==",
"'threshold_unit'",
":",
"for",
"bra... | Inflate a Parameter leaf according to unit type
Basic unit type are supposed by default
Other admissible unit types are threshold_unit and rate_unit | [
"Inflate",
"a",
"Parameter",
"leaf",
"according",
"to",
"unit",
"type"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/utils.py#L63-L121 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario.calculate_variable | def calculate_variable(self, variable = None, period = None, use_baseline = False):
"""
Compute and return the variable values for period and baseline or reform tax_benefit_system
"""
if use_baseline:
assert self.baseline_simulation is not None, "self.baseline_simulation is N... | python | def calculate_variable(self, variable = None, period = None, use_baseline = False):
"""
Compute and return the variable values for period and baseline or reform tax_benefit_system
"""
if use_baseline:
assert self.baseline_simulation is not None, "self.baseline_simulation is N... | [
"def",
"calculate_variable",
"(",
"self",
",",
"variable",
"=",
"None",
",",
"period",
"=",
"None",
",",
"use_baseline",
"=",
"False",
")",
":",
"if",
"use_baseline",
":",
"assert",
"self",
".",
"baseline_simulation",
"is",
"not",
"None",
",",
"\"self.baseli... | Compute and return the variable values for period and baseline or reform tax_benefit_system | [
"Compute",
"and",
"return",
"the",
"variable",
"values",
"for",
"period",
"and",
"baseline",
"or",
"reform",
"tax_benefit_system"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L298-L339 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario.filter_input_variables | def filter_input_variables(self, input_data_frame = None, simulation = None):
"""
Filter the input data frame from variables that won't be used or are set to be computed
"""
assert input_data_frame is not None
assert simulation is not None
id_variable_by_entity_key = self... | python | def filter_input_variables(self, input_data_frame = None, simulation = None):
"""
Filter the input data frame from variables that won't be used or are set to be computed
"""
assert input_data_frame is not None
assert simulation is not None
id_variable_by_entity_key = self... | [
"def",
"filter_input_variables",
"(",
"self",
",",
"input_data_frame",
"=",
"None",
",",
"simulation",
"=",
"None",
")",
":",
"assert",
"input_data_frame",
"is",
"not",
"None",
"assert",
"simulation",
"is",
"not",
"None",
"id_variable_by_entity_key",
"=",
"self",
... | Filter the input data frame from variables that won't be used or are set to be computed | [
"Filter",
"the",
"input",
"data",
"frame",
"from",
"variables",
"that",
"won",
"t",
"be",
"used",
"or",
"are",
"set",
"to",
"be",
"computed"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L523-L585 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario.init_from_data | def init_from_data(self, calibration_kwargs = None, inflation_kwargs = None,
rebuild_input_data = False, rebuild_kwargs = None, data = None, memory_config = None):
'''Initialises a survey scenario from data.
:param rebuild_input_data: Whether or not to clean, format and save data.
... | python | def init_from_data(self, calibration_kwargs = None, inflation_kwargs = None,
rebuild_input_data = False, rebuild_kwargs = None, data = None, memory_config = None):
'''Initialises a survey scenario from data.
:param rebuild_input_data: Whether or not to clean, format and save data.
... | [
"def",
"init_from_data",
"(",
"self",
",",
"calibration_kwargs",
"=",
"None",
",",
"inflation_kwargs",
"=",
"None",
",",
"rebuild_input_data",
"=",
"False",
",",
"rebuild_kwargs",
"=",
"None",
",",
"data",
"=",
"None",
",",
"memory_config",
"=",
"None",
")",
... | Initialises a survey scenario from data.
:param rebuild_input_data: Whether or not to clean, format and save data.
Take a look at :func:`build_input_data`
:param data: Contains the data, or metadata needed to know where to find it. | [
"Initialises",
"a",
"survey",
"scenario",
"from",
"data",
"."
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L628-L677 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario.neutralize_variables | def neutralize_variables(self, tax_benefit_system):
"""
Neutralizing input variables not in input dataframe and keep some crucial variables
"""
for variable_name, variable in tax_benefit_system.variables.items():
if variable.formulas:
continue
if s... | python | def neutralize_variables(self, tax_benefit_system):
"""
Neutralizing input variables not in input dataframe and keep some crucial variables
"""
for variable_name, variable in tax_benefit_system.variables.items():
if variable.formulas:
continue
if s... | [
"def",
"neutralize_variables",
"(",
"self",
",",
"tax_benefit_system",
")",
":",
"for",
"variable_name",
",",
"variable",
"in",
"tax_benefit_system",
".",
"variables",
".",
"items",
"(",
")",
":",
"if",
"variable",
".",
"formulas",
":",
"continue",
"if",
"self... | Neutralizing input variables not in input dataframe and keep some crucial variables | [
"Neutralizing",
"input",
"variables",
"not",
"in",
"input",
"dataframe",
"and",
"keep",
"some",
"crucial",
"variables"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L1020-L1034 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario.set_tax_benefit_systems | def set_tax_benefit_systems(self, tax_benefit_system = None, baseline_tax_benefit_system = None):
"""
Set the tax and benefit system and eventually the baseline tax and benefit system
"""
assert tax_benefit_system is not None
self.tax_benefit_system = tax_benefit_system
i... | python | def set_tax_benefit_systems(self, tax_benefit_system = None, baseline_tax_benefit_system = None):
"""
Set the tax and benefit system and eventually the baseline tax and benefit system
"""
assert tax_benefit_system is not None
self.tax_benefit_system = tax_benefit_system
i... | [
"def",
"set_tax_benefit_systems",
"(",
"self",
",",
"tax_benefit_system",
"=",
"None",
",",
"baseline_tax_benefit_system",
"=",
"None",
")",
":",
"assert",
"tax_benefit_system",
"is",
"not",
"None",
"self",
".",
"tax_benefit_system",
"=",
"tax_benefit_system",
"if",
... | Set the tax and benefit system and eventually the baseline tax and benefit system | [
"Set",
"the",
"tax",
"and",
"benefit",
"system",
"and",
"eventually",
"the",
"baseline",
"tax",
"and",
"benefit",
"system"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L1058-L1069 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario._set_id_variable_by_entity_key | def _set_id_variable_by_entity_key(self) -> Dict[str, str]:
'''Identify and set the good ids for the different entities'''
if self.id_variable_by_entity_key is None:
self.id_variable_by_entity_key = dict(
(entity.key, entity.key + '_id') for entity in self.tax_benefit_system.... | python | def _set_id_variable_by_entity_key(self) -> Dict[str, str]:
'''Identify and set the good ids for the different entities'''
if self.id_variable_by_entity_key is None:
self.id_variable_by_entity_key = dict(
(entity.key, entity.key + '_id') for entity in self.tax_benefit_system.... | [
"def",
"_set_id_variable_by_entity_key",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"str",
"]",
":",
"if",
"self",
".",
"id_variable_by_entity_key",
"is",
"None",
":",
"self",
".",
"id_variable_by_entity_key",
"=",
"dict",
"(",
"(",
"entity",
".",
"key... | Identify and set the good ids for the different entities | [
"Identify",
"and",
"set",
"the",
"good",
"ids",
"for",
"the",
"different",
"entities"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L1210-L1217 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario._set_role_variable_by_entity_key | def _set_role_variable_by_entity_key(self) -> Dict[str, str]:
'''Identify and set the good roles for the different entities'''
if self.role_variable_by_entity_key is None:
self.role_variable_by_entity_key = dict(
(entity.key, entity.key + '_legacy_role') for entity in self.ta... | python | def _set_role_variable_by_entity_key(self) -> Dict[str, str]:
'''Identify and set the good roles for the different entities'''
if self.role_variable_by_entity_key is None:
self.role_variable_by_entity_key = dict(
(entity.key, entity.key + '_legacy_role') for entity in self.ta... | [
"def",
"_set_role_variable_by_entity_key",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"str",
"]",
":",
"if",
"self",
".",
"role_variable_by_entity_key",
"is",
"None",
":",
"self",
".",
"role_variable_by_entity_key",
"=",
"dict",
"(",
"(",
"entity",
".",
... | Identify and set the good roles for the different entities | [
"Identify",
"and",
"set",
"the",
"good",
"roles",
"for",
"the",
"different",
"entities"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L1219-L1225 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scenarios.py | AbstractSurveyScenario._set_used_as_input_variables_by_entity | def _set_used_as_input_variables_by_entity(self) -> Dict[str, List[str]]:
'''Identify and set the good input variables for the different entities'''
if self.used_as_input_variables_by_entity is not None:
return
tax_benefit_system = self.tax_benefit_system
assert set(self.us... | python | def _set_used_as_input_variables_by_entity(self) -> Dict[str, List[str]]:
'''Identify and set the good input variables for the different entities'''
if self.used_as_input_variables_by_entity is not None:
return
tax_benefit_system = self.tax_benefit_system
assert set(self.us... | [
"def",
"_set_used_as_input_variables_by_entity",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
":",
"if",
"self",
".",
"used_as_input_variables_by_entity",
"is",
"not",
"None",
":",
"return",
"tax_benefit_system",
"=",
"self",
... | Identify and set the good input variables for the different entities | [
"Identify",
"and",
"set",
"the",
"good",
"input",
"variables",
"for",
"the",
"different",
"entities"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scenarios.py#L1227-L1248 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _ApparentDimensions._dimensions | def _dimensions(self):
"""tuple of dimension objects in this collection.
This composed tuple is the source for the dimension objects in this
collection.
"""
return tuple(d for d in self._all_dimensions if d.dimension_type != DT.MR_CAT) | python | def _dimensions(self):
"""tuple of dimension objects in this collection.
This composed tuple is the source for the dimension objects in this
collection.
"""
return tuple(d for d in self._all_dimensions if d.dimension_type != DT.MR_CAT) | [
"def",
"_dimensions",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"d",
"for",
"d",
"in",
"self",
".",
"_all_dimensions",
"if",
"d",
".",
"dimension_type",
"!=",
"DT",
".",
"MR_CAT",
")"
] | tuple of dimension objects in this collection.
This composed tuple is the source for the dimension objects in this
collection. | [
"tuple",
"of",
"dimension",
"objects",
"in",
"this",
"collection",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L80-L86 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _DimensionFactory._iter_dimensions | def _iter_dimensions(self):
"""Generate Dimension object for each dimension dict."""
return (
Dimension(raw_dimension.dimension_dict, raw_dimension.dimension_type)
for raw_dimension in self._raw_dimensions
) | python | def _iter_dimensions(self):
"""Generate Dimension object for each dimension dict."""
return (
Dimension(raw_dimension.dimension_dict, raw_dimension.dimension_type)
for raw_dimension in self._raw_dimensions
) | [
"def",
"_iter_dimensions",
"(",
"self",
")",
":",
"return",
"(",
"Dimension",
"(",
"raw_dimension",
".",
"dimension_dict",
",",
"raw_dimension",
".",
"dimension_type",
")",
"for",
"raw_dimension",
"in",
"self",
".",
"_raw_dimensions",
")"
] | Generate Dimension object for each dimension dict. | [
"Generate",
"Dimension",
"object",
"for",
"each",
"dimension",
"dict",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L105-L110 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _DimensionFactory._raw_dimensions | def _raw_dimensions(self):
"""Sequence of _RawDimension objects wrapping each dimension dict."""
return tuple(
_RawDimension(dimension_dict, self._dimension_dicts)
for dimension_dict in self._dimension_dicts
) | python | def _raw_dimensions(self):
"""Sequence of _RawDimension objects wrapping each dimension dict."""
return tuple(
_RawDimension(dimension_dict, self._dimension_dicts)
for dimension_dict in self._dimension_dicts
) | [
"def",
"_raw_dimensions",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"_RawDimension",
"(",
"dimension_dict",
",",
"self",
".",
"_dimension_dicts",
")",
"for",
"dimension_dict",
"in",
"self",
".",
"_dimension_dicts",
")"
] | Sequence of _RawDimension objects wrapping each dimension dict. | [
"Sequence",
"of",
"_RawDimension",
"objects",
"wrapping",
"each",
"dimension",
"dict",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L113-L118 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _RawDimension.dimension_type | def dimension_type(self):
"""Return member of DIMENSION_TYPE appropriate to dimension_dict."""
base_type = self._base_type
if base_type == "categorical":
return self._resolve_categorical()
if base_type == "enum.variable":
return self._resolve_array_type()
... | python | def dimension_type(self):
"""Return member of DIMENSION_TYPE appropriate to dimension_dict."""
base_type = self._base_type
if base_type == "categorical":
return self._resolve_categorical()
if base_type == "enum.variable":
return self._resolve_array_type()
... | [
"def",
"dimension_type",
"(",
"self",
")",
":",
"base_type",
"=",
"self",
".",
"_base_type",
"if",
"base_type",
"==",
"\"categorical\"",
":",
"return",
"self",
".",
"_resolve_categorical",
"(",
")",
"if",
"base_type",
"==",
"\"enum.variable\"",
":",
"return",
... | Return member of DIMENSION_TYPE appropriate to dimension_dict. | [
"Return",
"member",
"of",
"DIMENSION_TYPE",
"appropriate",
"to",
"dimension_dict",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L139-L152 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _RawDimension._base_type | def _base_type(self):
"""Return str like 'enum.numeric' representing dimension type.
This string is a 'type.subclass' concatenation of the str keys
used to identify the dimension type in the cube response JSON.
The '.subclass' suffix only appears where a subtype is present.
"""
... | python | def _base_type(self):
"""Return str like 'enum.numeric' representing dimension type.
This string is a 'type.subclass' concatenation of the str keys
used to identify the dimension type in the cube response JSON.
The '.subclass' suffix only appears where a subtype is present.
"""
... | [
"def",
"_base_type",
"(",
"self",
")",
":",
"type_class",
"=",
"self",
".",
"_dimension_dict",
"[",
"\"type\"",
"]",
"[",
"\"class\"",
"]",
"if",
"type_class",
"==",
"\"categorical\"",
":",
"return",
"\"categorical\"",
"if",
"type_class",
"==",
"\"enum\"",
":"... | Return str like 'enum.numeric' representing dimension type.
This string is a 'type.subclass' concatenation of the str keys
used to identify the dimension type in the cube response JSON.
The '.subclass' suffix only appears where a subtype is present. | [
"Return",
"str",
"like",
"enum",
".",
"numeric",
"representing",
"dimension",
"type",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L160-L173 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _RawDimension._resolve_array_type | def _resolve_array_type(self):
"""Return one of the ARRAY_TYPES members of DIMENSION_TYPE.
This method distinguishes between CA and MR dimensions. The return
value is only meaningful if the dimension is known to be of array
type (i.e. either CA or MR, base-type 'enum.variable').
... | python | def _resolve_array_type(self):
"""Return one of the ARRAY_TYPES members of DIMENSION_TYPE.
This method distinguishes between CA and MR dimensions. The return
value is only meaningful if the dimension is known to be of array
type (i.e. either CA or MR, base-type 'enum.variable').
... | [
"def",
"_resolve_array_type",
"(",
"self",
")",
":",
"next_raw_dimension",
"=",
"self",
".",
"_next_raw_dimension",
"if",
"next_raw_dimension",
"is",
"None",
":",
"return",
"DT",
".",
"CA",
"is_mr_subvar",
"=",
"(",
"next_raw_dimension",
".",
"_base_type",
"==",
... | Return one of the ARRAY_TYPES members of DIMENSION_TYPE.
This method distinguishes between CA and MR dimensions. The return
value is only meaningful if the dimension is known to be of array
type (i.e. either CA or MR, base-type 'enum.variable'). | [
"Return",
"one",
"of",
"the",
"ARRAY_TYPES",
"members",
"of",
"DIMENSION_TYPE",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L209-L225 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _RawDimension._resolve_categorical | def _resolve_categorical(self):
"""Return one of the categorical members of DIMENSION_TYPE.
This method distinguishes between CAT, CA_CAT, MR_CAT, and LOGICAL
dimension types, all of which have the base type 'categorical'. The
return value is only meaningful if the dimension is known to... | python | def _resolve_categorical(self):
"""Return one of the categorical members of DIMENSION_TYPE.
This method distinguishes between CAT, CA_CAT, MR_CAT, and LOGICAL
dimension types, all of which have the base type 'categorical'. The
return value is only meaningful if the dimension is known to... | [
"def",
"_resolve_categorical",
"(",
"self",
")",
":",
"if",
"self",
".",
"_is_array_cat",
":",
"return",
"DT",
".",
"MR_CAT",
"if",
"self",
".",
"_has_selected_category",
"else",
"DT",
".",
"CA_CAT",
"return",
"DT",
".",
"LOGICAL",
"if",
"self",
".",
"_has... | Return one of the categorical members of DIMENSION_TYPE.
This method distinguishes between CAT, CA_CAT, MR_CAT, and LOGICAL
dimension types, all of which have the base type 'categorical'. The
return value is only meaningful if the dimension is known to be one
of the categorical types (h... | [
"Return",
"one",
"of",
"the",
"categorical",
"members",
"of",
"DIMENSION_TYPE",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L227-L240 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | Dimension.inserted_hs_indices | def inserted_hs_indices(self):
"""list of int index of each inserted subtotal for the dimension.
Each value represents the position of a subtotal in the interleaved
sequence of elements and subtotals items.
"""
# ---don't do H&S insertions for CA and MR subvar dimensions---
... | python | def inserted_hs_indices(self):
"""list of int index of each inserted subtotal for the dimension.
Each value represents the position of a subtotal in the interleaved
sequence of elements and subtotals items.
"""
# ---don't do H&S insertions for CA and MR subvar dimensions---
... | [
"def",
"inserted_hs_indices",
"(",
"self",
")",
":",
"if",
"self",
".",
"dimension_type",
"in",
"DT",
".",
"ARRAY_TYPES",
":",
"return",
"[",
"]",
"return",
"[",
"idx",
"for",
"idx",
",",
"item",
"in",
"enumerate",
"(",
"self",
".",
"_iter_interleaved_item... | list of int index of each inserted subtotal for the dimension.
Each value represents the position of a subtotal in the interleaved
sequence of elements and subtotals items. | [
"list",
"of",
"int",
"index",
"of",
"each",
"inserted",
"subtotal",
"for",
"the",
"dimension",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L299-L315 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | Dimension.is_marginable | def is_marginable(self):
"""True if adding counts across this dimension axis is meaningful."""
return self.dimension_type not in {DT.CA, DT.MR, DT.MR_CAT, DT.LOGICAL} | python | def is_marginable(self):
"""True if adding counts across this dimension axis is meaningful."""
return self.dimension_type not in {DT.CA, DT.MR, DT.MR_CAT, DT.LOGICAL} | [
"def",
"is_marginable",
"(",
"self",
")",
":",
"return",
"self",
".",
"dimension_type",
"not",
"in",
"{",
"DT",
".",
"CA",
",",
"DT",
".",
"MR",
",",
"DT",
".",
"MR_CAT",
",",
"DT",
".",
"LOGICAL",
"}"
] | True if adding counts across this dimension axis is meaningful. | [
"True",
"if",
"adding",
"counts",
"across",
"this",
"dimension",
"axis",
"is",
"meaningful",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L318-L320 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | Dimension.labels | def labels(
self, include_missing=False, include_transforms=False, include_cat_ids=False
):
"""Return list of str labels for the elements of this dimension.
Returns a list of (label, element_id) pairs if *include_cat_ids* is
True. The `element_id` value in the second position of the... | python | def labels(
self, include_missing=False, include_transforms=False, include_cat_ids=False
):
"""Return list of str labels for the elements of this dimension.
Returns a list of (label, element_id) pairs if *include_cat_ids* is
True. The `element_id` value in the second position of the... | [
"def",
"labels",
"(",
"self",
",",
"include_missing",
"=",
"False",
",",
"include_transforms",
"=",
"False",
",",
"include_cat_ids",
"=",
"False",
")",
":",
"elements",
"=",
"self",
".",
"all_elements",
"if",
"include_missing",
"else",
"self",
".",
"valid_elem... | Return list of str labels for the elements of this dimension.
Returns a list of (label, element_id) pairs if *include_cat_ids* is
True. The `element_id` value in the second position of the pair is
None for subtotal items (which don't have an element-id). | [
"Return",
"list",
"of",
"str",
"labels",
"for",
"the",
"elements",
"of",
"this",
"dimension",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L322-L357 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | Dimension._iter_interleaved_items | def _iter_interleaved_items(self, elements):
"""Generate element or subtotal items in interleaved order.
This ordering corresponds to how value "rows" (or columns) are to
appear after subtotals have been inserted at their anchor locations.
Where more than one subtotal is anchored to the... | python | def _iter_interleaved_items(self, elements):
"""Generate element or subtotal items in interleaved order.
This ordering corresponds to how value "rows" (or columns) are to
appear after subtotals have been inserted at their anchor locations.
Where more than one subtotal is anchored to the... | [
"def",
"_iter_interleaved_items",
"(",
"self",
",",
"elements",
")",
":",
"subtotals",
"=",
"self",
".",
"_subtotals",
"for",
"subtotal",
"in",
"subtotals",
".",
"iter_for_anchor",
"(",
"\"top\"",
")",
":",
"yield",
"subtotal",
"for",
"element",
"in",
"element... | Generate element or subtotal items in interleaved order.
This ordering corresponds to how value "rows" (or columns) are to
appear after subtotals have been inserted at their anchor locations.
Where more than one subtotal is anchored to the same location, they
appear in their document or... | [
"Generate",
"element",
"or",
"subtotal",
"items",
"in",
"interleaved",
"order",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L391-L414 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | Dimension._subtotals | def _subtotals(self):
"""_Subtotals sequence object for this dimension.
The subtotals sequence provides access to any subtotal insertions
defined on this dimension.
"""
view = self._dimension_dict.get("references", {}).get("view", {})
# ---view can be both None and {}, t... | python | def _subtotals(self):
"""_Subtotals sequence object for this dimension.
The subtotals sequence provides access to any subtotal insertions
defined on this dimension.
"""
view = self._dimension_dict.get("references", {}).get("view", {})
# ---view can be both None and {}, t... | [
"def",
"_subtotals",
"(",
"self",
")",
":",
"view",
"=",
"self",
".",
"_dimension_dict",
".",
"get",
"(",
"\"references\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"\"view\"",
",",
"{",
"}",
")",
"insertion_dicts",
"=",
"(",
"[",
"]",
"if",
"view",
"i... | _Subtotals sequence object for this dimension.
The subtotals sequence provides access to any subtotal insertions
defined on this dimension. | [
"_Subtotals",
"sequence",
"object",
"for",
"this",
"dimension",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L417-L428 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _AllElements._elements | def _elements(self):
"""Composed tuple storing actual sequence of element objects."""
ElementCls, element_dicts = self._element_makings
return tuple(
ElementCls(element_dict, idx, element_dicts)
for idx, element_dict in enumerate(element_dicts)
) | python | def _elements(self):
"""Composed tuple storing actual sequence of element objects."""
ElementCls, element_dicts = self._element_makings
return tuple(
ElementCls(element_dict, idx, element_dicts)
for idx, element_dict in enumerate(element_dicts)
) | [
"def",
"_elements",
"(",
"self",
")",
":",
"ElementCls",
",",
"element_dicts",
"=",
"self",
".",
"_element_makings",
"return",
"tuple",
"(",
"ElementCls",
"(",
"element_dict",
",",
"idx",
",",
"element_dicts",
")",
"for",
"idx",
",",
"element_dict",
"in",
"e... | Composed tuple storing actual sequence of element objects. | [
"Composed",
"tuple",
"storing",
"actual",
"sequence",
"of",
"element",
"objects",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L524-L530 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _BaseElement.numeric_value | def numeric_value(self):
"""Numeric value assigned to element by user, np.nan if absent."""
numeric_value = self._element_dict.get("numeric_value")
return np.nan if numeric_value is None else numeric_value | python | def numeric_value(self):
"""Numeric value assigned to element by user, np.nan if absent."""
numeric_value = self._element_dict.get("numeric_value")
return np.nan if numeric_value is None else numeric_value | [
"def",
"numeric_value",
"(",
"self",
")",
":",
"numeric_value",
"=",
"self",
".",
"_element_dict",
".",
"get",
"(",
"\"numeric_value\"",
")",
"return",
"np",
".",
"nan",
"if",
"numeric_value",
"is",
"None",
"else",
"numeric_value"
] | Numeric value assigned to element by user, np.nan if absent. | [
"Numeric",
"value",
"assigned",
"to",
"element",
"by",
"user",
"np",
".",
"nan",
"if",
"absent",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L596-L599 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Element.label | def label(self):
"""str display-name for this element, '' when absent from cube response.
This property handles numeric, datetime and text variables, but also
subvar dimensions
"""
value = self._element_dict.get("value")
type_name = type(value).__name__
if type_... | python | def label(self):
"""str display-name for this element, '' when absent from cube response.
This property handles numeric, datetime and text variables, but also
subvar dimensions
"""
value = self._element_dict.get("value")
type_name = type(value).__name__
if type_... | [
"def",
"label",
"(",
"self",
")",
":",
"value",
"=",
"self",
".",
"_element_dict",
".",
"get",
"(",
"\"value\"",
")",
"type_name",
"=",
"type",
"(",
"value",
")",
".",
"__name__",
"if",
"type_name",
"==",
"\"NoneType\"",
":",
"return",
"\"\"",
"if",
"t... | str display-name for this element, '' when absent from cube response.
This property handles numeric, datetime and text variables, but also
subvar dimensions | [
"str",
"display",
"-",
"name",
"for",
"this",
"element",
"when",
"absent",
"from",
"cube",
"response",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L620-L644 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Subtotals._iter_valid_subtotal_dicts | def _iter_valid_subtotal_dicts(self):
"""Generate each insertion dict that represents a valid subtotal."""
for insertion_dict in self._insertion_dicts:
# ---skip any non-dicts---
if not isinstance(insertion_dict, dict):
continue
# ---skip any non-subt... | python | def _iter_valid_subtotal_dicts(self):
"""Generate each insertion dict that represents a valid subtotal."""
for insertion_dict in self._insertion_dicts:
# ---skip any non-dicts---
if not isinstance(insertion_dict, dict):
continue
# ---skip any non-subt... | [
"def",
"_iter_valid_subtotal_dicts",
"(",
"self",
")",
":",
"for",
"insertion_dict",
"in",
"self",
".",
"_insertion_dicts",
":",
"if",
"not",
"isinstance",
"(",
"insertion_dict",
",",
"dict",
")",
":",
"continue",
"if",
"insertion_dict",
".",
"get",
"(",
"\"fu... | Generate each insertion dict that represents a valid subtotal. | [
"Generate",
"each",
"insertion",
"dict",
"that",
"represents",
"a",
"valid",
"subtotal",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L681-L702 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Subtotals._subtotals | def _subtotals(self):
"""Composed tuple storing actual sequence of _Subtotal objects."""
return tuple(
_Subtotal(subtotal_dict, self.valid_elements)
for subtotal_dict in self._iter_valid_subtotal_dicts()
) | python | def _subtotals(self):
"""Composed tuple storing actual sequence of _Subtotal objects."""
return tuple(
_Subtotal(subtotal_dict, self.valid_elements)
for subtotal_dict in self._iter_valid_subtotal_dicts()
) | [
"def",
"_subtotals",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"_Subtotal",
"(",
"subtotal_dict",
",",
"self",
".",
"valid_elements",
")",
"for",
"subtotal_dict",
"in",
"self",
".",
"_iter_valid_subtotal_dicts",
"(",
")",
")"
] | Composed tuple storing actual sequence of _Subtotal objects. | [
"Composed",
"tuple",
"storing",
"actual",
"sequence",
"of",
"_Subtotal",
"objects",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L705-L710 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Subtotal.anchor | def anchor(self):
"""int or str indicating element under which to insert this subtotal.
An int anchor is the id of the dimension element (category or
subvariable) under which to place this subtotal. The return value can
also be one of 'top' or 'bottom'.
The return value default... | python | def anchor(self):
"""int or str indicating element under which to insert this subtotal.
An int anchor is the id of the dimension element (category or
subvariable) under which to place this subtotal. The return value can
also be one of 'top' or 'bottom'.
The return value default... | [
"def",
"anchor",
"(",
"self",
")",
":",
"anchor",
"=",
"self",
".",
"_subtotal_dict",
"[",
"\"anchor\"",
"]",
"try",
":",
"anchor",
"=",
"int",
"(",
"anchor",
")",
"if",
"anchor",
"not",
"in",
"self",
".",
"valid_elements",
".",
"element_ids",
":",
"re... | int or str indicating element under which to insert this subtotal.
An int anchor is the id of the dimension element (category or
subvariable) under which to place this subtotal. The return value can
also be one of 'top' or 'bottom'.
The return value defaults to 'bottom' for an anchor r... | [
"int",
"or",
"str",
"indicating",
"element",
"under",
"which",
"to",
"insert",
"this",
"subtotal",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L721-L739 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Subtotal.anchor_idx | def anchor_idx(self):
"""int or str representing index of anchor element in dimension.
When the anchor is an operation, like 'top' or 'bottom'
"""
anchor = self.anchor
if anchor in ["top", "bottom"]:
return anchor
return self.valid_elements.get_by_id(anchor).... | python | def anchor_idx(self):
"""int or str representing index of anchor element in dimension.
When the anchor is an operation, like 'top' or 'bottom'
"""
anchor = self.anchor
if anchor in ["top", "bottom"]:
return anchor
return self.valid_elements.get_by_id(anchor).... | [
"def",
"anchor_idx",
"(",
"self",
")",
":",
"anchor",
"=",
"self",
".",
"anchor",
"if",
"anchor",
"in",
"[",
"\"top\"",
",",
"\"bottom\"",
"]",
":",
"return",
"anchor",
"return",
"self",
".",
"valid_elements",
".",
"get_by_id",
"(",
"anchor",
")",
".",
... | int or str representing index of anchor element in dimension.
When the anchor is an operation, like 'top' or 'bottom' | [
"int",
"or",
"str",
"representing",
"index",
"of",
"anchor",
"element",
"in",
"dimension",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L742-L750 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Subtotal.addend_ids | def addend_ids(self):
"""tuple of int ids of elements contributing to this subtotal.
Any element id not present in the dimension or present but
representing missing data is excluded.
"""
return tuple(
arg
for arg in self._subtotal_dict.get("args", [])
... | python | def addend_ids(self):
"""tuple of int ids of elements contributing to this subtotal.
Any element id not present in the dimension or present but
representing missing data is excluded.
"""
return tuple(
arg
for arg in self._subtotal_dict.get("args", [])
... | [
"def",
"addend_ids",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"arg",
"for",
"arg",
"in",
"self",
".",
"_subtotal_dict",
".",
"get",
"(",
"\"args\"",
",",
"[",
"]",
")",
"if",
"arg",
"in",
"self",
".",
"valid_elements",
".",
"element_ids",
")"
] | tuple of int ids of elements contributing to this subtotal.
Any element id not present in the dimension or present but
representing missing data is excluded. | [
"tuple",
"of",
"int",
"ids",
"of",
"elements",
"contributing",
"to",
"this",
"subtotal",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L753-L763 | train |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | _Subtotal.addend_idxs | def addend_idxs(self):
"""tuple of int index of each addend element for this subtotal.
The length of the tuple is the same as that for `.addend_ids`, but
each value repesents the offset of that element within the dimension,
rather than its element id.
"""
return tuple(
... | python | def addend_idxs(self):
"""tuple of int index of each addend element for this subtotal.
The length of the tuple is the same as that for `.addend_ids`, but
each value repesents the offset of that element within the dimension,
rather than its element id.
"""
return tuple(
... | [
"def",
"addend_idxs",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"self",
".",
"valid_elements",
".",
"get_by_id",
"(",
"addend_id",
")",
".",
"index_in_valids",
"for",
"addend_id",
"in",
"self",
".",
"addend_ids",
")"
] | tuple of int index of each addend element for this subtotal.
The length of the tuple is the same as that for `.addend_ids`, but
each value repesents the offset of that element within the dimension,
rather than its element id. | [
"tuple",
"of",
"int",
"index",
"of",
"each",
"addend",
"element",
"for",
"this",
"subtotal",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L766-L776 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/scripts/build_collection.py | create_data_file_by_format | def create_data_file_by_format(directory_path = None):
"""
Browse subdirectories to extract stata and sas files
"""
stata_files = []
sas_files = []
for root, subdirs, files in os.walk(directory_path):
for file_name in files:
file_path = os.path.join(root, file_name)
... | python | def create_data_file_by_format(directory_path = None):
"""
Browse subdirectories to extract stata and sas files
"""
stata_files = []
sas_files = []
for root, subdirs, files in os.walk(directory_path):
for file_name in files:
file_path = os.path.join(root, file_name)
... | [
"def",
"create_data_file_by_format",
"(",
"directory_path",
"=",
"None",
")",
":",
"stata_files",
"=",
"[",
"]",
"sas_files",
"=",
"[",
"]",
"for",
"root",
",",
"subdirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"directory_path",
")",
":",
"for",
"fi... | Browse subdirectories to extract stata and sas files | [
"Browse",
"subdirectories",
"to",
"extract",
"stata",
"and",
"sas",
"files"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/scripts/build_collection.py#L55-L71 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.as_array | def as_array(
self,
include_missing=False,
weighted=True,
include_transforms_for_dims=None,
prune=False,
):
"""Return `ndarray` representing cube values.
Returns the tabular representation of the crunch cube. The returned
array has the same number of ... | python | def as_array(
self,
include_missing=False,
weighted=True,
include_transforms_for_dims=None,
prune=False,
):
"""Return `ndarray` representing cube values.
Returns the tabular representation of the crunch cube. The returned
array has the same number of ... | [
"def",
"as_array",
"(",
"self",
",",
"include_missing",
"=",
"False",
",",
"weighted",
"=",
"True",
",",
"include_transforms_for_dims",
"=",
"None",
",",
"prune",
"=",
"False",
",",
")",
":",
"array",
"=",
"self",
".",
"_as_array",
"(",
"include_missing",
... | Return `ndarray` representing cube values.
Returns the tabular representation of the crunch cube. The returned
array has the same number of dimensions as the cube. E.g. for
a cross-tab representation of a categorical and numerical variable,
the resulting cube will have two dimensions.
... | [
"Return",
"ndarray",
"representing",
"cube",
"values",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L81-L126 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.count | def count(self, weighted=True):
"""Return numberic count of rows considered for cube response."""
return self._measures.weighted_n if weighted else self._measures.unweighted_n | python | def count(self, weighted=True):
"""Return numberic count of rows considered for cube response."""
return self._measures.weighted_n if weighted else self._measures.unweighted_n | [
"def",
"count",
"(",
"self",
",",
"weighted",
"=",
"True",
")",
":",
"return",
"self",
".",
"_measures",
".",
"weighted_n",
"if",
"weighted",
"else",
"self",
".",
"_measures",
".",
"unweighted_n"
] | Return numberic count of rows considered for cube response. | [
"Return",
"numberic",
"count",
"of",
"rows",
"considered",
"for",
"cube",
"response",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L132-L134 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.index | def index(self, weighted=True, prune=False):
"""Return cube index measurement.
This function is deprecated. Use index_table from CubeSlice.
"""
warnings.warn(
"CrunchCube.index() is deprecated. Use CubeSlice.index_table().",
DeprecationWarning,
)
... | python | def index(self, weighted=True, prune=False):
"""Return cube index measurement.
This function is deprecated. Use index_table from CubeSlice.
"""
warnings.warn(
"CrunchCube.index() is deprecated. Use CubeSlice.index_table().",
DeprecationWarning,
)
... | [
"def",
"index",
"(",
"self",
",",
"weighted",
"=",
"True",
",",
"prune",
"=",
"False",
")",
":",
"warnings",
".",
"warn",
"(",
"\"CrunchCube.index() is deprecated. Use CubeSlice.index_table().\"",
",",
"DeprecationWarning",
",",
")",
"return",
"Index",
".",
"data"... | Return cube index measurement.
This function is deprecated. Use index_table from CubeSlice. | [
"Return",
"cube",
"index",
"measurement",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L189-L198 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.is_univariate_ca | def is_univariate_ca(self):
"""True if cube only contains a CA dimension-pair, in either order."""
return self.ndim == 2 and set(self.dim_types) == {DT.CA_SUBVAR, DT.CA_CAT} | python | def is_univariate_ca(self):
"""True if cube only contains a CA dimension-pair, in either order."""
return self.ndim == 2 and set(self.dim_types) == {DT.CA_SUBVAR, DT.CA_CAT} | [
"def",
"is_univariate_ca",
"(",
"self",
")",
":",
"return",
"self",
".",
"ndim",
"==",
"2",
"and",
"set",
"(",
"self",
".",
"dim_types",
")",
"==",
"{",
"DT",
".",
"CA_SUBVAR",
",",
"DT",
".",
"CA_CAT",
"}"
] | True if cube only contains a CA dimension-pair, in either order. | [
"True",
"if",
"cube",
"only",
"contains",
"a",
"CA",
"dimension",
"-",
"pair",
"in",
"either",
"order",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L228-L230 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.labels | def labels(self, include_missing=False, include_transforms_for_dims=False):
"""Gets labels for each cube's dimension.
Args
include_missing (bool): Include labels for missing values
Returns
labels (list of lists): Labels for each dimension
"""
return [
... | python | def labels(self, include_missing=False, include_transforms_for_dims=False):
"""Gets labels for each cube's dimension.
Args
include_missing (bool): Include labels for missing values
Returns
labels (list of lists): Labels for each dimension
"""
return [
... | [
"def",
"labels",
"(",
"self",
",",
"include_missing",
"=",
"False",
",",
"include_transforms_for_dims",
"=",
"False",
")",
":",
"return",
"[",
"dim",
".",
"labels",
"(",
"include_missing",
",",
"include_transforms_for_dims",
")",
"for",
"dim",
"in",
"self",
".... | Gets labels for each cube's dimension.
Args
include_missing (bool): Include labels for missing values
Returns
labels (list of lists): Labels for each dimension | [
"Gets",
"labels",
"for",
"each",
"cube",
"s",
"dimension",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L237-L249 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.margin | def margin(
self,
axis=None,
weighted=True,
include_missing=False,
include_transforms_for_dims=None,
prune=False,
include_mr_cat=False,
):
"""Get margin for the selected axis.
the selected axis. For MR variables, this is the sum of the selecte... | python | def margin(
self,
axis=None,
weighted=True,
include_missing=False,
include_transforms_for_dims=None,
prune=False,
include_mr_cat=False,
):
"""Get margin for the selected axis.
the selected axis. For MR variables, this is the sum of the selecte... | [
"def",
"margin",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"weighted",
"=",
"True",
",",
"include_missing",
"=",
"False",
",",
"include_transforms_for_dims",
"=",
"None",
",",
"prune",
"=",
"False",
",",
"include_mr_cat",
"=",
"False",
",",
")",
":",
"... | Get margin for the selected axis.
the selected axis. For MR variables, this is the sum of the selected
and non-selected slices.
Args
axis (int): Axis across the margin is calculated. If no axis is
provided the margin is calculated across all axis.
... | [
"Get",
"margin",
"for",
"the",
"selected",
"axis",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L251-L379 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.mr_dim_ind | def mr_dim_ind(self):
"""Return int, tuple of int, or None, representing MR indices.
The return value represents the index of each multiple-response (MR)
dimension in this cube. Return value is None if there are no MR
dimensions, and int if there is one MR dimension, and a tuple of int
... | python | def mr_dim_ind(self):
"""Return int, tuple of int, or None, representing MR indices.
The return value represents the index of each multiple-response (MR)
dimension in this cube. Return value is None if there are no MR
dimensions, and int if there is one MR dimension, and a tuple of int
... | [
"def",
"mr_dim_ind",
"(",
"self",
")",
":",
"indices",
"=",
"tuple",
"(",
"idx",
"for",
"idx",
",",
"d",
"in",
"enumerate",
"(",
"self",
".",
"dimensions",
")",
"if",
"d",
".",
"dimension_type",
"==",
"DT",
".",
"MR_SUBVAR",
")",
"if",
"indices",
"==... | Return int, tuple of int, or None, representing MR indices.
The return value represents the index of each multiple-response (MR)
dimension in this cube. Return value is None if there are no MR
dimensions, and int if there is one MR dimension, and a tuple of int
when there are more than ... | [
"Return",
"int",
"tuple",
"of",
"int",
"or",
"None",
"representing",
"MR",
"indices",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L387-L409 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.population_counts | def population_counts(
self,
population_size,
weighted=True,
include_missing=False,
include_transforms_for_dims=None,
prune=False,
):
"""Return counts scaled in proportion to overall population.
The return value is a numpy.ndarray object. Count values... | python | def population_counts(
self,
population_size,
weighted=True,
include_missing=False,
include_transforms_for_dims=None,
prune=False,
):
"""Return counts scaled in proportion to overall population.
The return value is a numpy.ndarray object. Count values... | [
"def",
"population_counts",
"(",
"self",
",",
"population_size",
",",
"weighted",
"=",
"True",
",",
"include_missing",
"=",
"False",
",",
"include_transforms_for_dims",
"=",
"None",
",",
"prune",
"=",
"False",
",",
")",
":",
"population_counts",
"=",
"[",
"sli... | Return counts scaled in proportion to overall population.
The return value is a numpy.ndarray object. Count values are scaled
proportionally to approximate their value if the entire population
had been sampled. This calculation is based on the estimated size of
the population provided a... | [
"Return",
"counts",
"scaled",
"in",
"proportion",
"to",
"overall",
"population",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L469-L512 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.proportions | def proportions(
self,
axis=None,
weighted=True,
include_transforms_for_dims=None,
include_mr_cat=False,
prune=False,
):
"""Return percentage values for cube as `numpy.ndarray`.
This function calculates the proportions across the selected axis
... | python | def proportions(
self,
axis=None,
weighted=True,
include_transforms_for_dims=None,
include_mr_cat=False,
prune=False,
):
"""Return percentage values for cube as `numpy.ndarray`.
This function calculates the proportions across the selected axis
... | [
"def",
"proportions",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"weighted",
"=",
"True",
",",
"include_transforms_for_dims",
"=",
"None",
",",
"include_mr_cat",
"=",
"False",
",",
"prune",
"=",
"False",
",",
")",
":",
"table",
"=",
"self",
".",
"_measu... | Return percentage values for cube as `numpy.ndarray`.
This function calculates the proportions across the selected axis
of a crunch cube. For most variable types, it means the value divided
by the margin value. For a multiple-response variable, the value is
divided by the sum of selecte... | [
"Return",
"percentage",
"values",
"for",
"cube",
"as",
"numpy",
".",
"ndarray",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L525-L613 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._denominator | def _denominator(self, weighted, include_transforms_for_dims, axis):
"""Calculate denominator for percentages.
Only include those H&S dimensions, across which we DON'T sum. These H&S
are needed because of the shape, when dividing. Those across dims
which are summed across MUST NOT be in... | python | def _denominator(self, weighted, include_transforms_for_dims, axis):
"""Calculate denominator for percentages.
Only include those H&S dimensions, across which we DON'T sum. These H&S
are needed because of the shape, when dividing. Those across dims
which are summed across MUST NOT be in... | [
"def",
"_denominator",
"(",
"self",
",",
"weighted",
",",
"include_transforms_for_dims",
",",
"axis",
")",
":",
"table",
"=",
"self",
".",
"_measure",
"(",
"weighted",
")",
".",
"raw_cube_array",
"new_axis",
"=",
"self",
".",
"_adjust_axis",
"(",
"axis",
")"... | Calculate denominator for percentages.
Only include those H&S dimensions, across which we DON'T sum. These H&S
are needed because of the shape, when dividing. Those across dims
which are summed across MUST NOT be included, because they would
change the result. | [
"Calculate",
"denominator",
"for",
"percentages",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L615-L630 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.scale_means | def scale_means(self, hs_dims=None, prune=False):
"""Get cube means."""
slices_means = [ScaleMeans(slice_).data for slice_ in self.slices]
if hs_dims and self.ndim > 1:
# Intersperse scale means with nans if H&S specified, and 2D. No
# need to modify 1D, as only one mean... | python | def scale_means(self, hs_dims=None, prune=False):
"""Get cube means."""
slices_means = [ScaleMeans(slice_).data for slice_ in self.slices]
if hs_dims and self.ndim > 1:
# Intersperse scale means with nans if H&S specified, and 2D. No
# need to modify 1D, as only one mean... | [
"def",
"scale_means",
"(",
"self",
",",
"hs_dims",
"=",
"None",
",",
"prune",
"=",
"False",
")",
":",
"slices_means",
"=",
"[",
"ScaleMeans",
"(",
"slice_",
")",
".",
"data",
"for",
"slice_",
"in",
"self",
".",
"slices",
"]",
"if",
"hs_dims",
"and",
... | Get cube means. | [
"Get",
"cube",
"means",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L658-L696 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.zscore | def zscore(self, weighted=True, prune=False, hs_dims=None):
"""Return ndarray with cube's zscore measurements.
Zscore is a measure of statistical significance of observed vs.
expected counts. It's only applicable to a 2D contingency tables.
For 3D cubes, the measures of separate slices ... | python | def zscore(self, weighted=True, prune=False, hs_dims=None):
"""Return ndarray with cube's zscore measurements.
Zscore is a measure of statistical significance of observed vs.
expected counts. It's only applicable to a 2D contingency tables.
For 3D cubes, the measures of separate slices ... | [
"def",
"zscore",
"(",
"self",
",",
"weighted",
"=",
"True",
",",
"prune",
"=",
"False",
",",
"hs_dims",
"=",
"None",
")",
":",
"res",
"=",
"[",
"s",
".",
"zscore",
"(",
"weighted",
",",
"prune",
",",
"hs_dims",
")",
"for",
"s",
"in",
"self",
".",... | Return ndarray with cube's zscore measurements.
Zscore is a measure of statistical significance of observed vs.
expected counts. It's only applicable to a 2D contingency tables.
For 3D cubes, the measures of separate slices are stacked together
and returned as the result.
:para... | [
"Return",
"ndarray",
"with",
"cube",
"s",
"zscore",
"measurements",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L707-L721 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.wishart_pairwise_pvals | def wishart_pairwise_pvals(self, axis=0):
"""Return matrices of column-comparison p-values as list of numpy.ndarrays.
Square, symmetric matrix along *axis* of pairwise p-values for the
null hypothesis that col[i] = col[j] for each pair of columns.
*axis* (int): axis along which to perf... | python | def wishart_pairwise_pvals(self, axis=0):
"""Return matrices of column-comparison p-values as list of numpy.ndarrays.
Square, symmetric matrix along *axis* of pairwise p-values for the
null hypothesis that col[i] = col[j] for each pair of columns.
*axis* (int): axis along which to perf... | [
"def",
"wishart_pairwise_pvals",
"(",
"self",
",",
"axis",
"=",
"0",
")",
":",
"return",
"[",
"slice_",
".",
"wishart_pairwise_pvals",
"(",
"axis",
"=",
"axis",
")",
"for",
"slice_",
"in",
"self",
".",
"slices",
"]"
] | Return matrices of column-comparison p-values as list of numpy.ndarrays.
Square, symmetric matrix along *axis* of pairwise p-values for the
null hypothesis that col[i] = col[j] for each pair of columns.
*axis* (int): axis along which to perform comparison. Only columns (0)
are implemen... | [
"Return",
"matrices",
"of",
"column",
"-",
"comparison",
"p",
"-",
"values",
"as",
"list",
"of",
"numpy",
".",
"ndarrays",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L723-L732 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._adjust_inserted_indices | def _adjust_inserted_indices(inserted_indices_list, prune_indices_list):
"""Adjust inserted indices, if there are pruned elements."""
# Created a copy, to preserve cached property
updated_inserted = [[i for i in dim_inds] for dim_inds in inserted_indices_list]
pruned_and_inserted = zip(p... | python | def _adjust_inserted_indices(inserted_indices_list, prune_indices_list):
"""Adjust inserted indices, if there are pruned elements."""
# Created a copy, to preserve cached property
updated_inserted = [[i for i in dim_inds] for dim_inds in inserted_indices_list]
pruned_and_inserted = zip(p... | [
"def",
"_adjust_inserted_indices",
"(",
"inserted_indices_list",
",",
"prune_indices_list",
")",
":",
"updated_inserted",
"=",
"[",
"[",
"i",
"for",
"i",
"in",
"dim_inds",
"]",
"for",
"dim_inds",
"in",
"inserted_indices_list",
"]",
"pruned_and_inserted",
"=",
"zip",... | Adjust inserted indices, if there are pruned elements. | [
"Adjust",
"inserted",
"indices",
"if",
"there",
"are",
"pruned",
"elements",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L800-L811 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._apply_missings | def _apply_missings(self, res, include_missing=False):
"""Return ndarray with missing and insertions as specified.
The return value is the result of the following operations on *res*,
which is a raw cube value array (raw meaning it has shape of original
cube response).
* Remove... | python | def _apply_missings(self, res, include_missing=False):
"""Return ndarray with missing and insertions as specified.
The return value is the result of the following operations on *res*,
which is a raw cube value array (raw meaning it has shape of original
cube response).
* Remove... | [
"def",
"_apply_missings",
"(",
"self",
",",
"res",
",",
"include_missing",
"=",
"False",
")",
":",
"element_idxs",
"=",
"tuple",
"(",
"(",
"d",
".",
"all_elements",
".",
"element_idxs",
"if",
"include_missing",
"else",
"d",
".",
"valid_elements",
".",
"eleme... | Return ndarray with missing and insertions as specified.
The return value is the result of the following operations on *res*,
which is a raw cube value array (raw meaning it has shape of original
cube response).
* Remove vectors (rows/cols) for missing elements if *include_missin*
... | [
"Return",
"ndarray",
"with",
"missing",
"and",
"insertions",
"as",
"specified",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L826-L849 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._as_array | def _as_array(
self,
include_missing=False,
get_non_selected=False,
weighted=True,
include_transforms_for_dims=False,
):
"""Get crunch cube as ndarray.
Args
include_missing (bool): Include rows/cols for missing values.
get_non_selected... | python | def _as_array(
self,
include_missing=False,
get_non_selected=False,
weighted=True,
include_transforms_for_dims=False,
):
"""Get crunch cube as ndarray.
Args
include_missing (bool): Include rows/cols for missing values.
get_non_selected... | [
"def",
"_as_array",
"(",
"self",
",",
"include_missing",
"=",
"False",
",",
"get_non_selected",
"=",
"False",
",",
"weighted",
"=",
"True",
",",
"include_transforms_for_dims",
"=",
"False",
",",
")",
":",
"return",
"self",
".",
"_apply_subtotals",
"(",
"self",... | Get crunch cube as ndarray.
Args
include_missing (bool): Include rows/cols for missing values.
get_non_selected (bool): Get non-selected slices for MR vars.
weighted (bool): Take weighted or unweighted counts.
include_transforms_for_dims (list): For which dims to... | [
"Get",
"crunch",
"cube",
"as",
"ndarray",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L878-L901 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._cube_dict | def _cube_dict(self):
"""dict containing raw cube response, parsed from JSON payload."""
try:
cube_response = self._cube_response_arg
# ---parse JSON to a dict when constructed with JSON---
cube_dict = (
cube_response
if isinstance(cube... | python | def _cube_dict(self):
"""dict containing raw cube response, parsed from JSON payload."""
try:
cube_response = self._cube_response_arg
# ---parse JSON to a dict when constructed with JSON---
cube_dict = (
cube_response
if isinstance(cube... | [
"def",
"_cube_dict",
"(",
"self",
")",
":",
"try",
":",
"cube_response",
"=",
"self",
".",
"_cube_response_arg",
"cube_dict",
"=",
"(",
"cube_response",
"if",
"isinstance",
"(",
"cube_response",
",",
"dict",
")",
"else",
"json",
".",
"loads",
"(",
"cube_resp... | dict containing raw cube response, parsed from JSON payload. | [
"dict",
"containing",
"raw",
"cube",
"response",
"parsed",
"from",
"JSON",
"payload",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L953-L969 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._fix_valid_indices | def _fix_valid_indices(cls, valid_indices, insertion_index, dim):
"""Add indices for H&S inserted elements."""
# TODO: make this accept an immutable sequence for valid_indices
# (a tuple) and return an immutable sequence rather than mutating an
# argument.
indices = np.array(sort... | python | def _fix_valid_indices(cls, valid_indices, insertion_index, dim):
"""Add indices for H&S inserted elements."""
# TODO: make this accept an immutable sequence for valid_indices
# (a tuple) and return an immutable sequence rather than mutating an
# argument.
indices = np.array(sort... | [
"def",
"_fix_valid_indices",
"(",
"cls",
",",
"valid_indices",
",",
"insertion_index",
",",
"dim",
")",
":",
"indices",
"=",
"np",
".",
"array",
"(",
"sorted",
"(",
"valid_indices",
"[",
"dim",
"]",
")",
")",
"slice_index",
"=",
"np",
".",
"sum",
"(",
... | Add indices for H&S inserted elements. | [
"Add",
"indices",
"for",
"H&S",
"inserted",
"elements",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1029-L1039 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._is_axis_allowed | def _is_axis_allowed(self, axis):
"""Check if axis are allowed.
In case the calculation is requested over CA items dimension, it is not
valid. It's valid in all other cases.
"""
if axis is None:
# If table direction was requested, we must ensure that each slice
... | python | def _is_axis_allowed(self, axis):
"""Check if axis are allowed.
In case the calculation is requested over CA items dimension, it is not
valid. It's valid in all other cases.
"""
if axis is None:
# If table direction was requested, we must ensure that each slice
... | [
"def",
"_is_axis_allowed",
"(",
"self",
",",
"axis",
")",
":",
"if",
"axis",
"is",
"None",
":",
"if",
"DT",
".",
"CA_SUBVAR",
"in",
"self",
".",
"dim_types",
"[",
"-",
"2",
":",
"]",
":",
"return",
"False",
"return",
"True",
"if",
"isinstance",
"(",
... | Check if axis are allowed.
In case the calculation is requested over CA items dimension, it is not
valid. It's valid in all other cases. | [
"Check",
"if",
"axis",
"are",
"allowed",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1084-L1114 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._measure | def _measure(self, weighted):
"""_BaseMeasure subclass representing primary measure for this cube.
If the cube response includes a means measure, the return value is
means. Otherwise it is counts, with the choice between weighted or
unweighted determined by *weighted*.
Note tha... | python | def _measure(self, weighted):
"""_BaseMeasure subclass representing primary measure for this cube.
If the cube response includes a means measure, the return value is
means. Otherwise it is counts, with the choice between weighted or
unweighted determined by *weighted*.
Note tha... | [
"def",
"_measure",
"(",
"self",
",",
"weighted",
")",
":",
"return",
"(",
"self",
".",
"_measures",
".",
"means",
"if",
"self",
".",
"_measures",
".",
"means",
"is",
"not",
"None",
"else",
"self",
".",
"_measures",
".",
"weighted_counts",
"if",
"weighted... | _BaseMeasure subclass representing primary measure for this cube.
If the cube response includes a means measure, the return value is
means. Otherwise it is counts, with the choice between weighted or
unweighted determined by *weighted*.
Note that weighted counts are provided on an "as-... | [
"_BaseMeasure",
"subclass",
"representing",
"primary",
"measure",
"for",
"this",
"cube",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1133-L1150 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._prune_3d_body | def _prune_3d_body(self, res, transforms):
"""Return masked array where mask indicates pruned vectors.
*res* is an ndarray (result). *transforms* is a list of ...
"""
mask = np.zeros(res.shape)
mr_dim_idxs = self.mr_dim_ind
for i, prune_inds in enumerate(self.prune_indi... | python | def _prune_3d_body(self, res, transforms):
"""Return masked array where mask indicates pruned vectors.
*res* is an ndarray (result). *transforms* is a list of ...
"""
mask = np.zeros(res.shape)
mr_dim_idxs = self.mr_dim_ind
for i, prune_inds in enumerate(self.prune_indi... | [
"def",
"_prune_3d_body",
"(",
"self",
",",
"res",
",",
"transforms",
")",
":",
"mask",
"=",
"np",
".",
"zeros",
"(",
"res",
".",
"shape",
")",
"mr_dim_idxs",
"=",
"self",
".",
"mr_dim_ind",
"for",
"i",
",",
"prune_inds",
"in",
"enumerate",
"(",
"self",... | Return masked array where mask indicates pruned vectors.
*res* is an ndarray (result). *transforms* is a list of ... | [
"Return",
"masked",
"array",
"where",
"mask",
"indicates",
"pruned",
"vectors",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1161-L1191 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube.prune_indices | def prune_indices(self, transforms=None):
"""Return indices of pruned rows and columns as list.
The return value has one of three possible forms:
* a 1-element list of row indices (in case of 1D cube)
* 2-element list of row and col indices (in case of 2D cube)
* n-element list... | python | def prune_indices(self, transforms=None):
"""Return indices of pruned rows and columns as list.
The return value has one of three possible forms:
* a 1-element list of row indices (in case of 1D cube)
* 2-element list of row and col indices (in case of 2D cube)
* n-element list... | [
"def",
"prune_indices",
"(",
"self",
",",
"transforms",
"=",
"None",
")",
":",
"if",
"self",
".",
"ndim",
">=",
"3",
":",
"return",
"self",
".",
"_prune_3d_indices",
"(",
"transforms",
")",
"def",
"prune_non_3d_indices",
"(",
"transforms",
")",
":",
"row_m... | Return indices of pruned rows and columns as list.
The return value has one of three possible forms:
* a 1-element list of row indices (in case of 1D cube)
* 2-element list of row and col indices (in case of 2D cube)
* n-element list of tuples of 2 elements (if it's 3D cube).
... | [
"Return",
"indices",
"of",
"pruned",
"rows",
"and",
"columns",
"as",
"list",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1256-L1305 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._pruning_base | def _pruning_base(self, axis=None, hs_dims=None):
"""Gets margin if across CAT dimension. Gets counts if across items.
Categorical variables are pruned based on their marginal values. If the
marginal is a 0 or a NaN, the corresponding row/column is pruned. In
case of a subvars (items) d... | python | def _pruning_base(self, axis=None, hs_dims=None):
"""Gets margin if across CAT dimension. Gets counts if across items.
Categorical variables are pruned based on their marginal values. If the
marginal is a 0 or a NaN, the corresponding row/column is pruned. In
case of a subvars (items) d... | [
"def",
"_pruning_base",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"hs_dims",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"_is_axis_allowed",
"(",
"axis",
")",
":",
"return",
"self",
".",
"as_array",
"(",
"weighted",
"=",
"False",
",",
"include_t... | Gets margin if across CAT dimension. Gets counts if across items.
Categorical variables are pruned based on their marginal values. If the
marginal is a 0 or a NaN, the corresponding row/column is pruned. In
case of a subvars (items) dimension, we only prune if all the counts
of the corr... | [
"Gets",
"margin",
"if",
"across",
"CAT",
"dimension",
".",
"Gets",
"counts",
"if",
"across",
"items",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1322-L1342 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | CrunchCube._update_result | def _update_result(self, result, insertions, dimension_index):
"""Insert subtotals into resulting ndarray."""
for j, (ind_insertion, value) in enumerate(insertions):
result = np.insert(
result, ind_insertion + j + 1, value, axis=dimension_index
)
return re... | python | def _update_result(self, result, insertions, dimension_index):
"""Insert subtotals into resulting ndarray."""
for j, (ind_insertion, value) in enumerate(insertions):
result = np.insert(
result, ind_insertion + j + 1, value, axis=dimension_index
)
return re... | [
"def",
"_update_result",
"(",
"self",
",",
"result",
",",
"insertions",
",",
"dimension_index",
")",
":",
"for",
"j",
",",
"(",
"ind_insertion",
",",
"value",
")",
"in",
"enumerate",
"(",
"insertions",
")",
":",
"result",
"=",
"np",
".",
"insert",
"(",
... | Insert subtotals into resulting ndarray. | [
"Insert",
"subtotals",
"into",
"resulting",
"ndarray",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1344-L1350 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | _Measures.means | def means(self):
"""_MeanMeasure object providing access to means values.
None when the cube response does not contain a mean measure.
"""
mean_measure_dict = (
self._cube_dict.get("result", {}).get("measures", {}).get("mean")
)
if mean_measure_dict is None:
... | python | def means(self):
"""_MeanMeasure object providing access to means values.
None when the cube response does not contain a mean measure.
"""
mean_measure_dict = (
self._cube_dict.get("result", {}).get("measures", {}).get("mean")
)
if mean_measure_dict is None:
... | [
"def",
"means",
"(",
"self",
")",
":",
"mean_measure_dict",
"=",
"(",
"self",
".",
"_cube_dict",
".",
"get",
"(",
"\"result\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"\"measures\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"\"mean\"",
")",
")",
"if",
... | _MeanMeasure object providing access to means values.
None when the cube response does not contain a mean measure. | [
"_MeanMeasure",
"object",
"providing",
"access",
"to",
"means",
"values",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1381-L1391 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | _Measures.missing_count | def missing_count(self):
"""numeric representing count of missing rows in cube response."""
if self.means:
return self.means.missing_count
return self._cube_dict["result"].get("missing", 0) | python | def missing_count(self):
"""numeric representing count of missing rows in cube response."""
if self.means:
return self.means.missing_count
return self._cube_dict["result"].get("missing", 0) | [
"def",
"missing_count",
"(",
"self",
")",
":",
"if",
"self",
".",
"means",
":",
"return",
"self",
".",
"means",
".",
"missing_count",
"return",
"self",
".",
"_cube_dict",
"[",
"\"result\"",
"]",
".",
"get",
"(",
"\"missing\"",
",",
"0",
")"
] | numeric representing count of missing rows in cube response. | [
"numeric",
"representing",
"count",
"of",
"missing",
"rows",
"in",
"cube",
"response",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1394-L1398 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | _Measures.weighted_counts | def weighted_counts(self):
"""_WeightedCountMeasure object for this cube.
This object provides access to weighted counts for this cube, if
available. If the cube response is not weighted, the
_UnweightedCountMeasure object for this cube is returned.
"""
if not self.is_we... | python | def weighted_counts(self):
"""_WeightedCountMeasure object for this cube.
This object provides access to weighted counts for this cube, if
available. If the cube response is not weighted, the
_UnweightedCountMeasure object for this cube is returned.
"""
if not self.is_we... | [
"def",
"weighted_counts",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_weighted",
":",
"return",
"self",
".",
"unweighted_counts",
"return",
"_WeightedCountMeasure",
"(",
"self",
".",
"_cube_dict",
",",
"self",
".",
"_all_dimensions",
")"
] | _WeightedCountMeasure object for this cube.
This object provides access to weighted counts for this cube, if
available. If the cube response is not weighted, the
_UnweightedCountMeasure object for this cube is returned. | [
"_WeightedCountMeasure",
"object",
"for",
"this",
"cube",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1433-L1442 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | _Measures.weighted_n | def weighted_n(self):
"""float count of returned rows adjusted for weighting."""
if not self.is_weighted:
return float(self.unweighted_n)
return float(sum(self._cube_dict["result"]["measures"]["count"]["data"])) | python | def weighted_n(self):
"""float count of returned rows adjusted for weighting."""
if not self.is_weighted:
return float(self.unweighted_n)
return float(sum(self._cube_dict["result"]["measures"]["count"]["data"])) | [
"def",
"weighted_n",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_weighted",
":",
"return",
"float",
"(",
"self",
".",
"unweighted_n",
")",
"return",
"float",
"(",
"sum",
"(",
"self",
".",
"_cube_dict",
"[",
"\"result\"",
"]",
"[",
"\"measures\""... | float count of returned rows adjusted for weighting. | [
"float",
"count",
"of",
"returned",
"rows",
"adjusted",
"for",
"weighting",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1445-L1449 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | _BaseMeasure.raw_cube_array | def raw_cube_array(self):
"""Return read-only ndarray of measure values from cube-response.
The shape of the ndarray mirrors the shape of the (raw) cube
response. Specifically, it includes values for missing elements, any
MR_CAT dimensions, and any prunable rows and columns.
"""... | python | def raw_cube_array(self):
"""Return read-only ndarray of measure values from cube-response.
The shape of the ndarray mirrors the shape of the (raw) cube
response. Specifically, it includes values for missing elements, any
MR_CAT dimensions, and any prunable rows and columns.
"""... | [
"def",
"raw_cube_array",
"(",
"self",
")",
":",
"array",
"=",
"np",
".",
"array",
"(",
"self",
".",
"_flat_values",
")",
".",
"reshape",
"(",
"self",
".",
"_all_dimensions",
".",
"shape",
")",
"array",
".",
"flags",
".",
"writeable",
"=",
"False",
"ret... | Return read-only ndarray of measure values from cube-response.
The shape of the ndarray mirrors the shape of the (raw) cube
response. Specifically, it includes values for missing elements, any
MR_CAT dimensions, and any prunable rows and columns. | [
"Return",
"read",
"-",
"only",
"ndarray",
"of",
"measure",
"values",
"from",
"cube",
"-",
"response",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1460-L1470 | train |
Crunch-io/crunch-cube | src/cr/cube/crunch_cube.py | _MeanMeasure._flat_values | def _flat_values(self):
"""Return tuple of mean values as found in cube response.
Mean data may include missing items represented by a dict like
{'?': -1} in the cube response. These are replaced by np.nan in the
returned value.
"""
return tuple(
np.nan if ty... | python | def _flat_values(self):
"""Return tuple of mean values as found in cube response.
Mean data may include missing items represented by a dict like
{'?': -1} in the cube response. These are replaced by np.nan in the
returned value.
"""
return tuple(
np.nan if ty... | [
"def",
"_flat_values",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"np",
".",
"nan",
"if",
"type",
"(",
"x",
")",
"is",
"dict",
"else",
"x",
"for",
"x",
"in",
"self",
".",
"_cube_dict",
"[",
"\"result\"",
"]",
"[",
"\"measures\"",
"]",
"[",
"\"m... | Return tuple of mean values as found in cube response.
Mean data may include missing items represented by a dict like
{'?': -1} in the cube response. These are replaced by np.nan in the
returned value. | [
"Return",
"tuple",
"of",
"mean",
"values",
"as",
"found",
"in",
"cube",
"response",
"."
] | a837840755690eb14b2ec8e8d93b4104e01c854f | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1490-L1500 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/input_dataframe_generator.py | make_input_dataframe_by_entity | def make_input_dataframe_by_entity(tax_benefit_system, nb_persons, nb_groups):
"""
Generate a dictionnary of dataframes containing nb_persons persons spread in nb_groups groups.
:param TaxBenefitSystem tax_benefit_system: the tax_benefit_system to use
:param int nb_persons: the number of pe... | python | def make_input_dataframe_by_entity(tax_benefit_system, nb_persons, nb_groups):
"""
Generate a dictionnary of dataframes containing nb_persons persons spread in nb_groups groups.
:param TaxBenefitSystem tax_benefit_system: the tax_benefit_system to use
:param int nb_persons: the number of pe... | [
"def",
"make_input_dataframe_by_entity",
"(",
"tax_benefit_system",
",",
"nb_persons",
",",
"nb_groups",
")",
":",
"input_dataframe_by_entity",
"=",
"dict",
"(",
")",
"person_entity",
"=",
"[",
"entity",
"for",
"entity",
"in",
"tax_benefit_system",
".",
"entities",
... | Generate a dictionnary of dataframes containing nb_persons persons spread in nb_groups groups.
:param TaxBenefitSystem tax_benefit_system: the tax_benefit_system to use
:param int nb_persons: the number of persons in the system
:param int nb_groups: the number of collective entities in the syst... | [
"Generate",
"a",
"dictionnary",
"of",
"dataframes",
"containing",
"nb_persons",
"persons",
"spread",
"in",
"nb_groups",
"groups",
"."
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/input_dataframe_generator.py#L25-L84 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/surveys.py | Survey.insert_table | def insert_table(self, label = None, name = None, **kwargs):
"""
Insert a table in the Survey object
"""
data_frame = kwargs.pop('data_frame', None)
if data_frame is None:
data_frame = kwargs.pop('dataframe', None)
to_hdf_kwargs = kwargs.pop('to_hdf_kwargs',... | python | def insert_table(self, label = None, name = None, **kwargs):
"""
Insert a table in the Survey object
"""
data_frame = kwargs.pop('data_frame', None)
if data_frame is None:
data_frame = kwargs.pop('dataframe', None)
to_hdf_kwargs = kwargs.pop('to_hdf_kwargs',... | [
"def",
"insert_table",
"(",
"self",
",",
"label",
"=",
"None",
",",
"name",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"data_frame",
"=",
"kwargs",
".",
"pop",
"(",
"'data_frame'",
",",
"None",
")",
"if",
"data_frame",
"is",
"None",
":",
"data_frame",... | Insert a table in the Survey object | [
"Insert",
"a",
"table",
"in",
"the",
"Survey",
"object"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/surveys.py#L248-L272 | train |
openfisca/openfisca-survey-manager | openfisca_survey_manager/variables.py | quantile | def quantile(q, variable, weight_variable = None, filter_variable = None):
"""
Return quantile of a variable with weight provided by a specific wieght variable potentially filtered
"""
def formula(entity, period):
value = entity(variable, period)
if weight_variable is not None:
... | python | def quantile(q, variable, weight_variable = None, filter_variable = None):
"""
Return quantile of a variable with weight provided by a specific wieght variable potentially filtered
"""
def formula(entity, period):
value = entity(variable, period)
if weight_variable is not None:
... | [
"def",
"quantile",
"(",
"q",
",",
"variable",
",",
"weight_variable",
"=",
"None",
",",
"filter_variable",
"=",
"None",
")",
":",
"def",
"formula",
"(",
"entity",
",",
"period",
")",
":",
"value",
"=",
"entity",
"(",
"variable",
",",
"period",
")",
"if... | Return quantile of a variable with weight provided by a specific wieght variable potentially filtered | [
"Return",
"quantile",
"of",
"a",
"variable",
"with",
"weight",
"provided",
"by",
"a",
"specific",
"wieght",
"variable",
"potentially",
"filtered"
] | bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358 | https://github.com/openfisca/openfisca-survey-manager/blob/bed6c65dc5e4ec2bdc9cda5b865fefd9e3d0c358/openfisca_survey_manager/variables.py#L12-L36 | train |
mgaitan/waliki | docs/conf.py | _get_version | def _get_version():
"""Get the version from package itself."""
with open("../waliki/__init__.py") as fh:
for line in fh:
if line.startswith("__version__ = "):
return line.split("=")[-1].strip().strip("'").strip('"') | python | def _get_version():
"""Get the version from package itself."""
with open("../waliki/__init__.py") as fh:
for line in fh:
if line.startswith("__version__ = "):
return line.split("=")[-1].strip().strip("'").strip('"') | [
"def",
"_get_version",
"(",
")",
":",
"with",
"open",
"(",
"\"../waliki/__init__.py\"",
")",
"as",
"fh",
":",
"for",
"line",
"in",
"fh",
":",
"if",
"line",
".",
"startswith",
"(",
"\"__version__ = \"",
")",
":",
"return",
"line",
".",
"split",
"(",
"\"=\... | Get the version from package itself. | [
"Get",
"the",
"version",
"from",
"package",
"itself",
"."
] | 5baaf6f043275920a1174ff233726f7ff4bfb5cf | https://github.com/mgaitan/waliki/blob/5baaf6f043275920a1174ff233726f7ff4bfb5cf/docs/conf.py#L27-L32 | train |
mgaitan/waliki | waliki/management/commands/moin_migration_cleanup.py | clean_meta | def clean_meta(rst_content):
"""remove moinmoin metada from the top of the file"""
rst = rst_content.split('\n')
for i, line in enumerate(rst):
if line.startswith('#'):
continue
break
return '\n'.join(rst[i:]) | python | def clean_meta(rst_content):
"""remove moinmoin metada from the top of the file"""
rst = rst_content.split('\n')
for i, line in enumerate(rst):
if line.startswith('#'):
continue
break
return '\n'.join(rst[i:]) | [
"def",
"clean_meta",
"(",
"rst_content",
")",
":",
"rst",
"=",
"rst_content",
".",
"split",
"(",
"'\\n'",
")",
"for",
"i",
",",
"line",
"in",
"enumerate",
"(",
"rst",
")",
":",
"if",
"line",
".",
"startswith",
"(",
"'#'",
")",
":",
"continue",
"break... | remove moinmoin metada from the top of the file | [
"remove",
"moinmoin",
"metada",
"from",
"the",
"top",
"of",
"the",
"file"
] | 5baaf6f043275920a1174ff233726f7ff4bfb5cf | https://github.com/mgaitan/waliki/blob/5baaf6f043275920a1174ff233726f7ff4bfb5cf/waliki/management/commands/moin_migration_cleanup.py#L21-L29 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.