text:
"""
A loc indexer for pandas-on-Spark DataFrame/Series.
"""
from abc import ABCMeta, abstractmethod
from collections.abc import Iterable
from functools import reduce
from typing import Any, Optional, List, Tuple, TYPE_CHECKING, Union, cast, Sized

import pandas as pd
from pandas.api.types import is_list_like  # type: ignore[attr-defined]
from pyspark.sql import functions as F, Column
from pyspark.sql.types import BooleanType, LongType, DataType
from pyspark.sql.utils import AnalysisException
import numpy as np

from pyspark import pandas as ps  # noqa: F401
from pyspark.pandas._typing import Label, Name, Scalar
from pyspark.pandas.internal import (
    DEFAULT_SERIES_NAME,
    InternalField,
    InternalFrame,
    NATURAL_ORDER_COLUMN_NAME,
    SPARK_DEFAULT_SERIES_NAME,
)
from pyspark.pandas.exceptions import SparkPandasIndexingError, SparkPandasNotImplementedError
from pyspark.pandas.spark import functions as SF
from pyspark.pandas.utils import (
    is_name_like_tuple,
    is_name_like_value,
    lazy_property,
    name_like_string,
    same_anchor,
    scol_for,
    spark_column_equals,
    verify_temp_column_name,
)

if TYPE_CHECKING:
    from pyspark.pandas.frame import DataFrame
    from pyspark.pandas.generic import Frame
    from pyspark.pandas.series import Series

class IndexerLike:
    def __init__(self, psdf_or_psser: "Frame"):
        from pyspark.pandas.frame import DataFrame
        from pyspark.pandas.series import Series

        assert isinstance(
            psdf_or_psser, (DataFrame, Series)
        ), "unexpected argument type: {}".format(type(psdf_or_psser))
        self._psdf_or_psser = psdf_or_psser

    @property
    def _is_df(self) -> bool:
        from pyspark.pandas.frame import DataFrame

        return isinstance(self._psdf_or_psser, DataFrame)

    @property
    def _is_series(self) -> bool:
        from pyspark.pandas.series import Series

        return isinstance(self._psdf_or_psser, Series)

    @property
    def _psdf(self) -> "DataFrame":
        if self._is_df:
            return cast("DataFrame", self._psdf_or_psser)
        else:
            assert self._is_series
            return self._psdf_or_psser._psdf

    @property
    def _internal(self) -> InternalFrame:
        return self._psdf._internal

class AtIndexer(IndexerLike):
    """
    Access a single value for a row/column label pair.
    If the index is not unique, all matching pairs are returned as an array.
    Similar to ``loc``, in that both provide label-based lookups. Use ``at`` if you only need to
    get a single value in a DataFrame or Series.

    .. note:: Unlike pandas, pandas-on-Spark only allows using ``at`` to get values but not to
        set them.

    .. note:: Warning: If ``row_index`` matches a lot of rows, large amounts of data will be
        fetched, potentially causing your machine to run out of memory.

    Raises
    ------
    KeyError
        When label does not exist in DataFrame

    Examples
    --------
    >>> psdf = ps.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
    ...                    index=[4, 5, 5], columns=['A', 'B', 'C'])
    >>> psdf
        A   B   C
    4   0   2   3
    5   0   4   1
    5  10  20  30

    Get value at specified row/column pair

    >>> psdf.at[4, 'B']
    2

    Get array if an index occurs multiple times

    >>> psdf.at[5, 'B']
    array([ 4, 20])
    """

    def __getitem__(self, key: Any) -> Union["Series", "DataFrame", Scalar]:
        if self._is_df:
            if not isinstance(key, tuple) or len(key) != 2:
                raise TypeError("Use DataFrame.at like .at[row_index, column_name]")
            row_sel, col_sel = key
        else:
            assert self._is_series, type(self._psdf_or_psser)
            if isinstance(key, tuple) and len(key) != 1:
                raise TypeError("Use Series.at like .at[row_index]")
            row_sel = key
            col_sel = self._psdf_or_psser._column_label

        if self._internal.index_level == 1:
            if not is_name_like_value(row_sel, allow_none=False, allow_tuple=False):
                raise ValueError("At based indexing on a single index can only have a single value")
            row_sel = (row_sel,)
        else:
            if not is_name_like_tuple(row_sel, allow_none=False):
                raise ValueError("At based indexing on multi-index can only have tuple values")

        if col_sel is not None:
            if not is_name_like_value(col_sel, allow_none=False):
                raise ValueError("At based indexing on multi-index can only have tuple values")
            if not is_name_like_tuple(col_sel):
                col_sel = (col_sel,)

        cond = reduce(
            lambda x, y: x & y,
            [scol == row for scol, row in zip(self._internal.index_spark_columns, row_sel)],
        )
        pdf = (
            self._internal.spark_frame.drop(NATURAL_ORDER_COLUMN_NAME)
            .filter(cond)
            .select(self._internal.spark_column_for(col_sel))
            .toPandas()
        )

        if len(pdf) < 1:
            raise KeyError(name_like_string(row_sel))

        values = cast(pd.DataFrame, pdf).iloc[:, 0].values
        return (
            values if (len(row_sel) < self._internal.index_level or len(values) > 1) else values[0]
        )

class iAtIndexer(IndexerLike):
    """
    Access a single value for a row/column pair by integer position.

    Similar to ``iloc``, in that both provide integer-based lookups. Use
    ``iat`` if you only need to get or set a single value in a DataFrame
    or Series.

    Raises
    ------
    KeyError
        When label does not exist in DataFrame

    Examples
    --------
    >>> df = ps.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
    ...                   columns=['A', 'B', 'C'])
    >>> df
        A   B   C
    0   0   2   3
    1   0   4   1
    2  10  20  30

    Get value at specified row/column pair

    >>> df.iat[1, 2]
    1

    Get value within a series

    >>> psser = ps.Series([1, 2, 3], index=[10, 20, 30])
    >>> psser
    10    1
    20    2
    30    3
    dtype: int64

    >>> psser.iat[1]
    2
    """

    def __getitem__(self, key: Any) -> Union["Series", "DataFrame", Scalar]:
        if self._is_df:
            if not isinstance(key, tuple) or len(key) != 2:
                raise TypeError(
                    "Use DataFrame.iat like .iat[row_integer_position, column_integer_position]"
                )
            row_sel, col_sel = key
            if not isinstance(row_sel, int) or not isinstance(col_sel, int):
                raise ValueError("iAt based indexing can only have integer indexers")
            return self._psdf_or_psser.iloc[row_sel, col_sel]
        else:
            assert self._is_series, type(self._psdf_or_psser)
            if not isinstance(key, int) and len(key) != 1:
                raise TypeError("Use Series.iat like .iat[row_integer_position]")
            if not isinstance(key, int):
                raise ValueError("iAt based indexing can only have integer indexers")
            return self._psdf_or_psser.iloc[key]

class LocIndexerLike(IndexerLike, metaclass=ABCMeta):
    def _select_rows(self, rows_sel: Any) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        """
        Dispatch the logic for select rows to more specific methods by `rows_sel` argument types.

        Parameters
        ----------
        rows_sel : the key specified to select rows.

        Returns
        -------
        Tuple of Spark column, int, int:

            * The Spark column for the condition to filter the rows.
            * The number of rows when the selection can be simplified by limit.
            * The remaining index rows if the result index size is shrunk.
        """
        from pyspark.pandas.series import Series

        if rows_sel is None:
            return None, None, None
        elif isinstance(rows_sel, Series):
            return self._select_rows_by_series(rows_sel)
        elif isinstance(rows_sel, Column):
            return self._select_rows_by_spark_column(rows_sel)
        elif isinstance(rows_sel, slice):
            if rows_sel == slice(None):
                # If slice is None - select everything, so nothing to do
                return None, None, None
            return self._select_rows_by_slice(rows_sel)
        elif isinstance(rows_sel, tuple):
            return self._select_rows_else(rows_sel)
        elif is_list_like(rows_sel):
            return self._select_rows_by_iterable(rows_sel)
        else:
            return self._select_rows_else(rows_sel)

    def _select_cols(
        self, cols_sel: Any, missing_keys: Optional[List[Name]] = None
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        """
        Dispatch the logic for select columns to more specific methods by `cols_sel` argument types.

        Parameters
        ----------
        cols_sel : the key specified to select columns.

        Returns
        -------
        Tuple of list of column label, list of Spark columns, list of dtypes, bool:

            * The column labels selected.
            * The Spark columns selected.
            * The field metadata selected.
            * The boolean value whether Series should be returned or not.
            * The Series name if needed.
        """
        from pyspark.pandas.series import Series

        if cols_sel is None:
            column_labels = self._internal.column_labels
            data_spark_columns = self._internal.data_spark_columns
            data_fields = self._internal.data_fields
            return column_labels, data_spark_columns, data_fields, False, None
        elif isinstance(cols_sel, Series):
            return self._select_cols_by_series(cols_sel, missing_keys)
        elif isinstance(cols_sel, Column):
            return self._select_cols_by_spark_column(cols_sel, missing_keys)
        elif isinstance(cols_sel, slice):
            if cols_sel == slice(None):
                # If slice is None - select everything, so nothing to do
                column_labels = self._internal.column_labels
                data_spark_columns = self._internal.data_spark_columns
                data_fields = self._internal.data_fields
                return column_labels, data_spark_columns, data_fields, False, None
            return self._select_cols_by_slice(cols_sel, missing_keys)
        elif isinstance(cols_sel, tuple):
            return self._select_cols_else(cols_sel, missing_keys)
        elif is_list_like(cols_sel):
            return self._select_cols_by_iterable(cols_sel, missing_keys)
        else:
            return self._select_cols_else(cols_sel, missing_keys)

    # Methods for row selection

    @abstractmethod
    def _select_rows_by_series(
        self, rows_sel: "Series"
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        """Select rows by `Series` type key."""
        pass

    @abstractmethod
    def _select_rows_by_spark_column(
        self, rows_sel: Column
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        """Select rows by Spark `Column` type key."""
        pass

    @abstractmethod
    def _select_rows_by_slice(
        self, rows_sel: slice
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        """Select rows by `slice` type key."""
        pass

    @abstractmethod
    def _select_rows_by_iterable(
        self, rows_sel: Iterable
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        """Select rows by `Iterable` type key."""
        pass

    @abstractmethod
    def _select_rows_else(
        self, rows_sel: Any
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        """Select rows by other type key."""
        pass

    # Methods for col selection

    @abstractmethod
    def _select_cols_by_series(
        self, cols_sel: "Series", missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        """Select columns by `Series` type key."""
        pass

    @abstractmethod
    def _select_cols_by_spark_column(
        self, cols_sel: Column, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        """Select columns by Spark `Column` type key."""
        pass

    @abstractmethod
    def _select_cols_by_slice(
        self, cols_sel: slice, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        """Select columns by `slice` type key."""
        pass

    @abstractmethod
    def _select_cols_by_iterable(
        self, cols_sel: Iterable, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        """Select columns by `Iterable` type key."""
        pass

    @abstractmethod
    def _select_cols_else(
        self, cols_sel: Any, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        """Select columns by other type key."""
        pass

    def __getitem__(self, key: Any) -> Union["Series", "DataFrame"]:
        from pyspark.pandas.frame import DataFrame
        from pyspark.pandas.series import Series, first_series

        if self._is_series:
            if isinstance(key, Series) and not same_anchor(key, self._psdf_or_psser):
                name = self._psdf_or_psser.name or DEFAULT_SERIES_NAME
                psdf = self._psdf_or_psser.to_frame(name)
                temp_col = verify_temp_column_name(psdf, "__temp_col__")

                psdf[temp_col] = key
                return type(self)(psdf[name].rename(self._psdf_or_psser.name))[psdf[temp_col]]

            cond, limit, remaining_index = self._select_rows(key)
            if cond is None and limit is None:
                return self._psdf_or_psser

            column_label = self._psdf_or_psser._column_label
            column_labels = [column_label]
            data_spark_columns = [self._internal.spark_column_for(column_label)]
            data_fields = [self._internal.field_for(column_label)]
            returns_series = True
            series_name = self._psdf_or_psser.name
        else:
            assert self._is_df
            if isinstance(key, tuple):
                if len(key) != 2:
                    raise SparkPandasIndexingError("Only accepts pairs of candidates")
                rows_sel, cols_sel = key
            else:
                rows_sel = key
                cols_sel = None

            if isinstance(rows_sel, Series) and not same_anchor(rows_sel, self._psdf_or_psser):
                psdf = self._psdf_or_psser.copy()
                temp_col = verify_temp_column_name(cast("DataFrame", psdf), "__temp_col__")

                psdf[temp_col] = rows_sel
                return type(self)(psdf)[psdf[temp_col], cols_sel][list(self._psdf_or_psser.columns)]

            cond, limit, remaining_index = self._select_rows(rows_sel)
            (
                column_labels,
                data_spark_columns,
                data_fields,
                returns_series,
                series_name,
            ) = self._select_cols(cols_sel)

            if cond is None and limit is None and returns_series:
                psser = self._psdf_or_psser._psser_for(column_labels[0])
                if series_name is not None and series_name != psser.name:
                    psser = psser.rename(series_name)
                return psser

        if remaining_index is not None:
            index_spark_columns = self._internal.index_spark_columns[-remaining_index:]
            index_names = self._internal.index_names[-remaining_index:]
            index_fields = self._internal.index_fields[-remaining_index:]
        else:
            index_spark_columns = self._internal.index_spark_columns
            index_names = self._internal.index_names
            index_fields = self._internal.index_fields

        if len(column_labels) > 0:
            column_labels = column_labels.copy()
            column_labels_level = max(
                len(label) if label is not None else 1 for label in column_labels
            )
            none_column = 0
            for i, label in enumerate(column_labels):
                if label is None:
                    label = (none_column,)
                    none_column += 1
                if len(label) < column_labels_level:
                    label = tuple(list(label) + ([""]) * (column_labels_level - len(label)))
                column_labels[i] = label

            if i == 0 and none_column == 1:
                column_labels = [None]

            column_label_names = self._internal.column_label_names[-column_labels_level:]
        else:
            column_label_names = self._internal.column_label_names

        try:
            sdf = self._internal.spark_frame

            if cond is not None:
                index_columns = sdf.select(index_spark_columns).columns
                data_columns = sdf.select(data_spark_columns).columns
                sdf = sdf.filter(cond).select(index_spark_columns + data_spark_columns)
                index_spark_columns = [scol_for(sdf, col) for col in index_columns]
                data_spark_columns = [scol_for(sdf, col) for col in data_columns]

            if limit is not None:
                if limit >= 0:
                    sdf = sdf.limit(limit)
                else:
                    sdf = sdf.limit(sdf.count() + limit)
                sdf = sdf.drop(NATURAL_ORDER_COLUMN_NAME)
        except AnalysisException:
            raise KeyError(
                "[{}] don't exist in columns".format(
                    [col._jc.toString() for col in data_spark_columns]  # type: ignore[operator]
                )
            )

        internal = InternalFrame(
            spark_frame=sdf,
            index_spark_columns=index_spark_columns,
            index_names=index_names,
            index_fields=index_fields,
            column_labels=column_labels,
            data_spark_columns=data_spark_columns,
            data_fields=data_fields,
            column_label_names=column_label_names,
        )
        psdf = DataFrame(internal)

        psdf_or_psser: Union[DataFrame, Series]
        if returns_series:
            psdf_or_psser = cast(Series, first_series(psdf))
            if series_name is not None and series_name != psdf_or_psser.name:
                psdf_or_psser = psdf_or_psser.rename(series_name)
        else:
            psdf_or_psser = psdf

        if remaining_index is not None and remaining_index == 0:
            pdf_or_pser = psdf_or_psser.head(2)._to_pandas()
            length = len(pdf_or_pser)
            if length == 0:
                raise KeyError(name_like_string(key))
            elif length == 1:
                return pdf_or_pser.iloc[0]
            else:
                return psdf_or_psser
        else:
            return psdf_or_psser

    def __setitem__(self, key: Any, value: Any) -> None:
        from pyspark.pandas.frame import DataFrame
        from pyspark.pandas.series import Series, first_series

        if self._is_series:
            if (
                isinstance(key, Series)
                and (isinstance(self, iLocIndexer) or not same_anchor(key, self._psdf_or_psser))
            ) or (
                isinstance(value, Series)
                and (isinstance(self, iLocIndexer) or not same_anchor(value, self._psdf_or_psser))
            ):
                if self._psdf_or_psser.name is None:
                    psdf = self._psdf_or_psser.to_frame()
                    column_label = psdf._internal.column_labels[0]
                else:
                    psdf = self._psdf_or_psser._psdf.copy()
                    column_label = self._psdf_or_psser._column_label
                temp_natural_order = verify_temp_column_name(psdf, "__temp_natural_order__")
                temp_key_col = verify_temp_column_name(psdf, "__temp_key_col__")
                temp_value_col = verify_temp_column_name(psdf, "__temp_value_col__")

                psdf[temp_natural_order] = F.monotonically_increasing_id()
                if isinstance(key, Series):
                    psdf[temp_key_col] = key
                if isinstance(value, Series):
                    psdf[temp_value_col] = value
                psdf = psdf.sort_values(temp_natural_order).drop(columns=temp_natural_order)

                psser = psdf._psser_for(column_label)
                if isinstance(key, Series):
                    key = F.col(
                        "`{}`".format(psdf[temp_key_col]._internal.data_spark_column_names[0])
                    )
                if isinstance(value, Series):
                    value = F.col(
                        "`{}`".format(psdf[temp_value_col]._internal.data_spark_column_names[0])
                    )

                type(self)(psser)[key] = value

                if self._psdf_or_psser.name is None:
                    psser = psser.rename()

                self._psdf_or_psser._psdf._update_internal_frame(
                    psser._psdf[
                        self._psdf_or_psser._psdf._internal.column_labels
                    ]._internal.resolved_copy,
                    requires_same_anchor=False,
                )
                return

            if isinstance(value, DataFrame):
                raise ValueError("Incompatible indexer with DataFrame")

            cond, limit, remaining_index = self._select_rows(key)
            if cond is None:
                cond = SF.lit(True)
            if limit is not None:
                cond = cond & (
                    self._internal.spark_frame[cast(iLocIndexer, self)._sequence_col]
                    < SF.lit(limit)
                )

            if isinstance(value, (Series, Column)):
                if remaining_index is not None and remaining_index == 0:
                    raise ValueError(
                        "No axis named {} for object type {}".format(key, type(value).__name__)
                    )
                if isinstance(value, Series):
                    value = value.spark.column
            else:
                value = SF.lit(value)
            scol = (
                F.when(cond, value)
                .otherwise(self._internal.spark_column_for(self._psdf_or_psser._column_label))
                .alias(name_like_string(self._psdf_or_psser.name or SPARK_DEFAULT_SERIES_NAME))
            )

            internal = self._internal.with_new_spark_column(
                self._psdf_or_psser._column_label, scol  # TODO: dtype?
            )
            self._psdf_or_psser._psdf._update_internal_frame(internal, requires_same_anchor=False)
        else:
            assert self._is_df

            if isinstance(key, tuple):
                if len(key) != 2:
                    raise SparkPandasIndexingError("Only accepts pairs of candidates")
                rows_sel, cols_sel = key
            else:
                rows_sel = key
                cols_sel = None

            if isinstance(value, DataFrame):
                if len(value.columns) == 1:
                    value = first_series(value)
                else:
                    raise ValueError("Only a dataframe with one column can be assigned")

            if (
                isinstance(rows_sel, Series)
                and (
                    isinstance(self, iLocIndexer) or not same_anchor(rows_sel, self._psdf_or_psser)
                )
            ) or (
                isinstance(value, Series)
                and (isinstance(self, iLocIndexer) or not same_anchor(value, self._psdf_or_psser))
            ):
                psdf = cast(DataFrame, self._psdf_or_psser.copy())
                temp_natural_order = verify_temp_column_name(psdf, "__temp_natural_order__")
                temp_key_col = verify_temp_column_name(psdf, "__temp_key_col__")
                temp_value_col = verify_temp_column_name(psdf, "__temp_value_col__")

                psdf[temp_natural_order] = F.monotonically_increasing_id()
                if isinstance(rows_sel, Series):
                    psdf[temp_key_col] = rows_sel
                if isinstance(value, Series):
                    psdf[temp_value_col] = value
                psdf = psdf.sort_values(temp_natural_order).drop(columns=temp_natural_order)

                if isinstance(rows_sel, Series):
                    rows_sel = F.col(
                        "`{}`".format(psdf[temp_key_col]._internal.data_spark_column_names[0])
                    )
                if isinstance(value, Series):
                    value = F.col(
                        "`{}`".format(psdf[temp_value_col]._internal.data_spark_column_names[0])
                    )

                type(self)(psdf)[rows_sel, cols_sel] = value

                self._psdf_or_psser._update_internal_frame(
                    psdf[list(self._psdf_or_psser.columns)]._internal.resolved_copy,
                    requires_same_anchor=False,
                )
                return

            cond, limit, remaining_index = self._select_rows(rows_sel)
            missing_keys: List[Name] = []
            _, data_spark_columns, _, _, _ = self._select_cols(cols_sel, missing_keys=missing_keys)

            if cond is None:
                cond = SF.lit(True)
            if limit is not None:
                cond = cond & (
                    self._internal.spark_frame[cast(iLocIndexer, self)._sequence_col]
                    < SF.lit(limit)
                )

            if isinstance(value, (Series, Column)):
                if remaining_index is not None and remaining_index == 0:
                    raise ValueError("Incompatible indexer with Series")
                if len(data_spark_columns) > 1:
                    raise ValueError("shape mismatch")
                if isinstance(value, Series):
                    value = value.spark.column
            else:
                value = SF.lit(value)

            new_data_spark_columns = []
            new_fields = []
            for new_scol, spark_column_name, new_field in zip(
                self._internal.data_spark_columns,
                self._internal.data_spark_column_names,
                self._internal.data_fields,
            ):
                for scol in data_spark_columns:
                    if spark_column_equals(new_scol, scol):
                        new_scol = F.when(cond, value).otherwise(scol).alias(spark_column_name)
                        new_field = InternalField.from_struct_field(
                            self._internal.spark_frame.select(new_scol).schema[0],
                            use_extension_dtypes=new_field.is_extension_dtype,
                        )
                        break
                new_data_spark_columns.append(new_scol)
                new_fields.append(new_field)

            column_labels = self._internal.column_labels.copy()
            for missing in missing_keys:
                if is_name_like_tuple(missing):
                    label = cast(Label, missing)
                else:
                    label = cast(Label, (missing,))
                if len(label) < self._internal.column_labels_level:
                    label = tuple(
                        list(label) + ([""] * (self._internal.column_labels_level - len(label)))
                    )
                elif len(label) > self._internal.column_labels_level:
                    raise KeyError(
                        "Key length ({}) exceeds index depth ({})".format(
                            len(label), self._internal.column_labels_level
                        )
                    )
                column_labels.append(label)
                new_data_spark_columns.append(F.when(cond, value).alias(name_like_string(label)))
                new_fields.append(None)

            internal = self._internal.with_new_columns(
                new_data_spark_columns, column_labels=column_labels, data_fields=new_fields
            )
            self._psdf_or_psser._update_internal_frame(internal, requires_same_anchor=False)

class LocIndexer(LocIndexerLike):
    """
    Access a group of rows and columns by label(s) or a boolean Series.

    ``.loc[]`` is primarily label based, but may also be used with a
    conditional boolean Series derived from the DataFrame or Series.

    Allowed inputs are:

    - A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is
      interpreted as a *label* of the index, and **never** as an
      integer position along the index) for column selection.

    - A list or array of labels, e.g. ``['a', 'b', 'c']``.

    - A slice object with labels, e.g. ``'a':'f'``.

    - A conditional boolean Series derived from the DataFrame or Series

    - A boolean array of the same length as the column axis being sliced,
      e.g. ``[True, False, True]``.

    - An alignable boolean pandas Series to the column axis being sliced.
      The index of the key will be aligned before masking.

    Not allowed inputs which pandas allows are:

    - A boolean array of the same length as the row axis being sliced,
      e.g. ``[True, False, True]``.
    - A ``callable`` function with one argument (the calling Series, DataFrame
      or Panel) and that returns valid output for indexing (one of the above)

    .. note:: MultiIndex is not supported yet.

    .. note:: Note that contrary to usual python slices, **both** the
        start and the stop are included, and the step of the slice is not allowed.

    .. note:: With a list or array of labels for row selection,
        pandas-on-Spark behaves as a filter without reordering by the labels.

    See Also
    --------
    Series.loc : Access group of values using labels.

    Examples
    --------
    **Getting values**

    >>> df = ps.DataFrame([[1, 2], [4, 5], [7, 8]],
    ...                   index=['cobra', 'viper', 'sidewinder'],
    ...                   columns=['max_speed', 'shield'])
    >>> df
                max_speed  shield
    cobra               1       2
    viper               4       5
    sidewinder          7       8

    Single label. Note this returns the row as a Series.

    >>> df.loc['viper']
    max_speed    4
    shield       5
    Name: viper, dtype: int64

    List of labels. Note using ``[[]]`` returns a DataFrame.
    Also note that pandas-on-Spark behaves just a filter without reordering by the labels.

    >>> df.loc[['viper', 'sidewinder']]
                max_speed  shield
    viper               4       5
    sidewinder          7       8

    >>> df.loc[['sidewinder', 'viper']]
                max_speed  shield
    viper               4       5
    sidewinder          7       8

    Single label for column.

    >>> df.loc['cobra', 'shield']
    2

    List of labels for row.

    >>> df.loc[['cobra'], 'shield']
    cobra    2
    Name: shield, dtype: int64

    List of labels for column.

    >>> df.loc['cobra', ['shield']]
    shield    2
    Name: cobra, dtype: int64

    List of labels for both row and column.

    >>> df.loc[['cobra'], ['shield']]
           shield
    cobra       2

    Slice with labels for row and single label for column. As mentioned
    above, note that both the start and stop of the slice are included.

    >>> df.loc['cobra':'viper', 'max_speed']
    cobra    1
    viper    4
    Name: max_speed, dtype: int64

    Conditional that returns a boolean Series

    >>> df.loc[df['shield'] > 6]
                max_speed  shield
    sidewinder          7       8

    Conditional that returns a boolean Series with column labels specified

    >>> df.loc[df['shield'] > 6, ['max_speed']]
                max_speed
    sidewinder          7

    A boolean array of the same length as the column axis being sliced.

    >>> df.loc[:, [False, True]]
                shield
    cobra            2
    viper            5
    sidewinder       8

    An alignable boolean Series to the column axis being sliced.

    >>> df.loc[:, pd.Series([False, True], index=['max_speed', 'shield'])]
                shield
    cobra            2
    viper            5
    sidewinder       8

    **Setting values**

    Setting value for all items matching the list of labels.

    >>> df.loc[['viper', 'sidewinder'], ['shield']] = 50
    >>> df
                max_speed  shield
    cobra               1       2
    viper               4      50
    sidewinder          7      50

    Setting value for an entire row

    >>> df.loc['cobra'] = 10
    >>> df
                max_speed  shield
    cobra              10      10
    viper               4      50
    sidewinder          7      50

    Set value for an entire column

    >>> df.loc[:, 'max_speed'] = 30
    >>> df
                max_speed  shield
    cobra              30      10
    viper              30      50
    sidewinder         30      50

    Set value for an entire list of columns

    >>> df.loc[:, ['max_speed', 'shield']] = 100
    >>> df
                max_speed  shield
    cobra             100     100
    viper             100     100
    sidewinder        100     100

    Set value with Series

    >>> df.loc[:, 'shield'] = df['shield'] * 2
    >>> df
                max_speed  shield
    cobra             100     200
    viper             100     200
    sidewinder        100     200

    **Getting values on a DataFrame with an index that has integer labels**

    Another example using integers for the index

    >>> df = ps.DataFrame([[1, 2], [4, 5], [7, 8]],
    ...                   index=[7, 8, 9],
    ...                   columns=['max_speed', 'shield'])
    >>> df
       max_speed  shield
    7          1       2
    8          4       5
    9          7       8

    Slice with integer labels for rows. As mentioned above, note that both
    the start and stop of the slice are included.

    >>> df.loc[7:9]
       max_speed  shield
    7          1       2
    8          4       5
    9          7       8
    """

    @staticmethod
    def _NotImplemented(description: str) -> SparkPandasNotImplementedError:
        return SparkPandasNotImplementedError(
            description=description,
            pandas_function=".loc[..., ...]",
            spark_target_function="select, where",
        )

    def _select_rows_by_series(
        self, rows_sel: "Series"
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        assert isinstance(rows_sel.spark.data_type, BooleanType), rows_sel.spark.data_type
        return rows_sel.spark.column, None, None

    def _select_rows_by_spark_column(
        self, rows_sel: Column
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        spark_type = self._internal.spark_frame.select(rows_sel).schema[0].dataType
        assert isinstance(spark_type, BooleanType), spark_type
        return rows_sel, None, None

    def _select_rows_by_slice(
        self, rows_sel: slice
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        from pyspark.pandas.indexes import MultiIndex

        if rows_sel.step is not None:
            raise LocIndexer._NotImplemented("Cannot use step with Spark.")
        elif self._internal.index_level == 1:
            sdf = self._internal.spark_frame
            index = self._psdf_or_psser.index
            index_column = index.to_series()
            index_data_type = index_column.spark.data_type
            start = rows_sel.start
            stop = rows_sel.stop

            # get natural order from '__natural_order__' from start to stop
            # to keep natural order.
            start_and_stop = (
                sdf.select(index_column.spark.column, NATURAL_ORDER_COLUMN_NAME)
                .where(
                    (index_column.spark.column == SF.lit(start).cast(index_data_type))
                    | (index_column.spark.column == SF.lit(stop).cast(index_data_type))
                )
                .collect()
            )

            start = [row[1] for row in start_and_stop if row[0] == start]
            start = start[0] if len(start) > 0 else None

            stop = [row[1] for row in start_and_stop if row[0] == stop]
            stop = stop[-1] if len(stop) > 0 else None

            conds: List[Column] = []
            if start is not None:
                conds.append(F.col(NATURAL_ORDER_COLUMN_NAME) >= SF.lit(start).cast(LongType()))
            if stop is not None:
                conds.append(F.col(NATURAL_ORDER_COLUMN_NAME) <= SF.lit(stop).cast(LongType()))

            # if index order is not monotonic increasing or decreasing
            # and specified values don't exist in index, raise KeyError
            if (start is None and rows_sel.start is not None) or (
                stop is None and rows_sel.stop is not None
            ):

                inc = index_column.is_monotonic_increasing
                if inc is False:
                    dec = index_column.is_monotonic_decreasing

                if start is None and rows_sel.start is not None:
                    start = rows_sel.start
                    if inc is not False:
                        conds.append(
                            index_column.spark.column >= SF.lit(start).cast(index_data_type)
                        )
                    elif dec is not False:
                        conds.append(
                            index_column.spark.column <= SF.lit(start).cast(index_data_type)
                        )
                    else:
                        raise KeyError(rows_sel.start)
                if stop is None and rows_sel.stop is not None:
                    stop = rows_sel.stop
                    if inc is not False:
                        conds.append(
                            index_column.spark.column <= SF.lit(stop).cast(index_data_type)
                        )
                    elif dec is not False:
                        conds.append(
                            index_column.spark.column >= SF.lit(stop).cast(index_data_type)
                        )
                    else:
                        raise KeyError(rows_sel.stop)

            return reduce(lambda x, y: x & y, conds), None, None
        else:
            from pyspark.sql.types import StructType

            index = self._psdf_or_psser.index
            index_data_type = [  # type: ignore[assignment]
                f.dataType for f in cast(StructType, index.to_series().spark.data_type)
            ]

            start = rows_sel.start
            if start is not None:
                if not isinstance(start, tuple):
                    start = (start,)
                if len(start) == 0:
                    start = None
            stop = rows_sel.stop
            if stop is not None:
                if not isinstance(stop, tuple):
                    stop = (stop,)
                if len(stop) == 0:
                    stop = None

            depth = max(
                len(start) if start is not None else 0, len(stop) if stop is not None else 0
            )
            if depth == 0:
                return None, None, None
            elif (
                depth > self._internal.index_level
                or not index.droplevel(list(range(self._internal.index_level)[depth:])).is_monotonic
            ):
                raise KeyError(
                    "Key length ({}) was greater than MultiIndex sort depth".format(depth)
                )

            conds = []
            if start is not None:
                cond = SF.lit(True)
                for scol, value, dt in list(
                    zip(
                        self._internal.index_spark_columns,
                        cast(Tuple[int, ...], start),
                        cast(List[DataType], index_data_type),
                    )
                )[::-1]:
                    compare = MultiIndex._comparator_for_monotonic_increasing(dt)
                    cond = F.when(scol.eqNullSafe(SF.lit(value).cast(dt)), cond).otherwise(
                        compare(scol, SF.lit(value).cast(dt), Column.__gt__)
                    )
                conds.append(cond)
            if stop is not None:
                cond = SF.lit(True)
                for scol, value, dt in list(
                    zip(
                        self._internal.index_spark_columns,
                        cast(Tuple[int, ...], stop),
                        cast(List[DataType], index_data_type),
                    )
                )[::-1]:
                    compare = MultiIndex._comparator_for_monotonic_increasing(dt)
                    cond = F.when(scol.eqNullSafe(SF.lit(value).cast(dt)), cond).otherwise(
                        compare(scol, SF.lit(value).cast(dt), Column.__lt__)
                    )
                conds.append(cond)

            return reduce(lambda x, y: x & y, conds), None, None

    def _select_rows_by_iterable(
        self, rows_sel: Iterable
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        rows_sel = list(rows_sel)
        if len(rows_sel) == 0:
            return SF.lit(False), None, None
        elif self._internal.index_level == 1:
            index_column = self._psdf_or_psser.index.to_series()
            index_data_type = index_column.spark.data_type
            if len(rows_sel) == 1:
                return (
                    index_column.spark.column == SF.lit(rows_sel[0]).cast(index_data_type),
                    None,
                    None,
                )
            else:
                return (
                    index_column.spark.column.isin(
                        [SF.lit(r).cast(index_data_type) for r in rows_sel]
                    ),
                    None,
                    None,
                )
        else:
            raise LocIndexer._NotImplemented("Cannot select with MultiIndex with Spark.")

    def _select_rows_else(
        self, rows_sel: Any
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        if not isinstance(rows_sel, tuple):
            rows_sel = (rows_sel,)
        if len(rows_sel) > self._internal.index_level:
            raise SparkPandasIndexingError("Too many indexers")

        rows = [scol == value for scol, value in zip(self._internal.index_spark_columns, rows_sel)]
        return (
            reduce(lambda x, y: x & y, rows),
            None,
            self._internal.index_level - len(rows_sel),
        )

    def _get_from_multiindex_column(
        self,
        key: Optional[Label],
        missing_keys: Optional[List[Name]],
        labels: Optional[List[Tuple[Label, Label]]] = None,
        recursed: int = 0,
    ) -> Tuple[List[Label], Optional[List[Column]], List[InternalField], bool, Optional[Name]]:
        """Select columns from multi-index columns."""
        assert isinstance(key, tuple)
        if labels is None:
            labels = [(label, label) for label in self._internal.column_labels]
        for k in key:
            labels = [
                (label, None if lbl is None else lbl[1:])
                for label, lbl in labels
                if (lbl is None and k is None) or (lbl is not None and lbl[0] == k)
            ]
            if len(labels) == 0:
                if missing_keys is None:
                    raise KeyError(k)
                else:
                    missing_keys.append(key)
                    return [], [], [], False, None

        if all(lbl is not None and len(lbl) > 0 and lbl[0] == "" for _, lbl in labels):
            # If the head is '', drill down recursively.
            labels = [(label, tuple([str(key), *lbl[1:]])) for i, (label, lbl) in enumerate(labels)]
            return self._get_from_multiindex_column((str(key),), missing_keys, labels, recursed + 1)
        else:
            returns_series = all(lbl is None or len(lbl) == 0 for _, lbl in labels)
            series_name: Optional[Name]
            if returns_series:
                label_set = set(label for label, _ in labels)
                assert len(label_set) == 1
                label = list(label_set)[0]
                column_labels = [label]
                data_spark_columns = [self._internal.spark_column_for(label)]
                data_fields = [self._internal.field_for(label)]
                if label is None:
                    series_name = None
                else:
                    if recursed > 0:
                        label = label[:-recursed]
                    series_name = label if len(label) > 1 else label[0]
            else:
                column_labels = [
                    None if lbl is None or lbl == (None,) else lbl for _, lbl in labels
                ]
                data_spark_columns = [self._internal.spark_column_for(label) for label, _ in labels]
                data_fields = [self._internal.field_for(label) for label, _ in labels]
                series_name = None

            return column_labels, data_spark_columns, data_fields, returns_series, series_name

    def _select_cols_by_series(
        self, cols_sel: "Series", missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        column_labels = cols_sel._internal.column_labels
        data_spark_columns = cols_sel._internal.data_spark_columns
        data_fields = cols_sel._internal.data_fields
        return column_labels, data_spark_columns, data_fields, True, None

    def _select_cols_by_spark_column(
        self, cols_sel: Column, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        column_labels: List[Label] = [(self._internal.spark_frame.select(cols_sel).columns[0],)]
        data_spark_columns = [cols_sel]
        return column_labels, data_spark_columns, None, True, None

    def _select_cols_by_slice(
        self, cols_sel: slice, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        start, stop = self._psdf_or_psser.columns.slice_locs(
            start=cols_sel.start, end=cols_sel.stop
        )
        column_labels = self._internal.column_labels[start:stop]
        data_spark_columns = self._internal.data_spark_columns[start:stop]
        data_fields = self._internal.data_fields[start:stop]
        return column_labels, data_spark_columns, data_fields, False, None

    def _select_cols_by_iterable(
        self, cols_sel: Iterable, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        from pyspark.pandas.series import Series

        if all(isinstance(key, Series) for key in cols_sel):
            column_labels = [key._column_label for key in cols_sel]
            data_spark_columns = [key.spark.column for key in cols_sel]
            data_fields = [key._internal.data_fields[0] for key in cols_sel]
        elif all(isinstance(key, Column) for key in cols_sel):
            column_labels = [
                (self._internal.spark_frame.select(col).columns[0],) for col in cols_sel
            ]
            data_spark_columns = list(cols_sel)
            data_fields = None
        elif all(isinstance(key, bool) for key in cols_sel) or all(
            isinstance(key, np.bool_) for key in cols_sel
        ):
            if len(cast(Sized, cols_sel)) != len(self._internal.column_labels):
                raise IndexError(
                    "Boolean index has wrong length: %s instead of %s"
                    % (len(cast(Sized, cols_sel)), len(self._internal.column_labels))
                )
            if isinstance(cols_sel, pd.Series):
                if not cols_sel.index.sort_values().equals(self._psdf.columns.sort_values()):
                    raise SparkPandasIndexingError(
                        "Unalignable boolean Series provided as indexer "
                        "(index of the boolean Series and of the indexed object do not match)"
                    )
                else:
                    column_labels = [
                        column_label
                        for column_label in self._internal.column_labels
                        if cols_sel[column_label if len(column_label) > 1 else column_label[0]]
                    ]
                    data_spark_columns = [
                        self._internal.spark_column_for(column_label)
                        for column_label in column_labels
                    ]
                    data_fields = [
                        self._internal.field_for(column_label) for column_label in column_labels
                    ]
            else:
                column_labels = [
                    self._internal.column_labels[i] for i, col in enumerate(cols_sel) if col
                ]
                data_spark_columns = [
                    self._internal.data_spark_columns[i] for i, col in enumerate(cols_sel) if col
                ]
                data_fields = [
                    self._internal.data_fields[i] for i, col in enumerate(cols_sel) if col
                ]
        elif any(isinstance(key, tuple) for key in cols_sel) and any(
            not is_name_like_tuple(key) for key in cols_sel
        ):
            raise TypeError(
                "Expected tuple, got {}".format(
                    type(set(key for key in cols_sel if not is_name_like_tuple(key)).pop())
                )
            )
        else:
            if missing_keys is None and all(isinstance(key, tuple) for key in cols_sel):
                level = self._internal.column_labels_level
                if any(len(key) != level for key in cols_sel):
                    raise ValueError("All the key level should be the same as column index level.")

            column_labels = []
            data_spark_columns = []
            data_fields = []
            for key in cols_sel:
                found = False
                for label in self._internal.column_labels:
                    if label == key or label[0] == key:
                        column_labels.append(label)
                        data_spark_columns.append(self._internal.spark_column_for(label))
                        data_fields.append(self._internal.field_for(label))
                        found = True
                if not found:
                    if missing_keys is None:
                        raise KeyError("['{}'] not in index".format(name_like_string(key)))
                    else:
                        missing_keys.append(key)

        return column_labels, data_spark_columns, data_fields, False, None

    def _select_cols_else(
        self, cols_sel: Any, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        if not is_name_like_tuple(cols_sel):
            cols_sel = (cols_sel,)
        return self._get_from_multiindex_column(cols_sel, missing_keys)

class iLocIndexer(LocIndexerLike):
    """
    Purely integer-location based indexing for selection by position.

    ``.iloc[]`` is primarily integer position based (from ``0`` to
    ``length-1`` of the axis), but may also be used with a conditional boolean Series.

    Allowed inputs are:

    - An integer for column selection, e.g. ``5``.
    - A list or array of integers for row selection with distinct index values,
      e.g. ``[3, 4, 0]``
    - A list or array of integers for column selection, e.g. ``[4, 3, 0]``.
    - A boolean array for column selection.
    - A slice object with ints for row and column selection, e.g. ``1:7``.

    Not allowed inputs which pandas allows are:

    - A list or array of integers for row selection with duplicated indexes,
      e.g. ``[4, 4, 0]``.
    - A boolean array for row selection.
    - A ``callable`` function with one argument (the calling Series, DataFrame
      or Panel) and that returns valid output for indexing (one of the above).
      This is useful in method chains, when you don't have a reference to the
      calling object, but would like to base your selection on some value.

    ``.iloc`` will raise ``IndexError`` if a requested indexer is
    out-of-bounds, except *slice* indexers which allow out-of-bounds
    indexing (this conforms with python/numpy *slice* semantics).

    See Also
    --------
    DataFrame.loc : Purely label-location based indexer for selection by label.
    Series.iloc : Purely integer-location based indexing for
                   selection by position.

    Examples
    --------

    >>> mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
    ...           {'a': 100, 'b': 200, 'c': 300, 'd': 400},
    ...           {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
    >>> df = ps.DataFrame(mydict, columns=['a', 'b', 'c', 'd'])
    >>> df
          a     b     c     d
    0     1     2     3     4
    1   100   200   300   400
    2  1000  2000  3000  4000

    **Indexing just the rows**

    A scalar integer for row selection.

    >>> df.iloc[1]
    a    100
    b    200
    c    300
    d    400
    Name: 1, dtype: int64

    >>> df.iloc[[0]]
       a  b  c  d
    0  1  2  3  4

    With a `slice` object.

    >>> df.iloc[:3]
          a     b     c     d
    0     1     2     3     4
    1   100   200   300   400
    2  1000  2000  3000  4000

    **Indexing both axes**

    You can mix the indexer types for the index and columns. Use ``:`` to
    select the entire axis.

    With scalar integers.

    >>> df.iloc[:1, 1]
    0    2
    Name: b, dtype: int64

    With lists of integers.

    >>> df.iloc[:2, [1, 3]]
         b    d
    0    2    4
    1  200  400

    With `slice` objects.

    >>> df.iloc[:2, 0:3]
         a    b    c
    0    1    2    3
    1  100  200  300

    With a boolean array whose length matches the columns.

    >>> df.iloc[:, [True, False, True, False]]
          a     c
    0     1     3
    1   100   300
    2  1000  3000

    **Setting values**

    Setting value for all items matching the list of labels.

    >>> df.iloc[[1, 2], [1]] = 50
    >>> df
          a   b     c     d
    0     1   2     3     4
    1   100  50   300   400
    2  1000  50  3000  4000

    Setting value for an entire row

    >>> df.iloc[0] = 10
    >>> df
          a   b     c     d
    0    10  10    10    10
    1   100  50   300   400
    2  1000  50  3000  4000

    Set value for an entire column

    >>> df.iloc[:, 2] = 30
    >>> df
          a   b   c     d
    0    10  10  30    10
    1   100  50  30   400
    2  1000  50  30  4000

    Set value for an entire list of columns

    >>> df.iloc[:, [2, 3]] = 100
    >>> df
          a   b    c    d
    0    10  10  100  100
    1   100  50  100  100
    2  1000  50  100  100

    Set value with Series

    >>> df.iloc[:, 3] = df.iloc[:, 3] * 2
    >>> df
          a   b    c    d
    0    10  10  100  200
    1   100  50  100  200
    2  1000  50  100  200
    """

    @staticmethod
    def _NotImplemented(description: str) -> SparkPandasNotImplementedError:
        return SparkPandasNotImplementedError(
            description=description,
            pandas_function=".iloc[..., ...]",
            spark_target_function="select, where",
        )

    @lazy_property
    def _internal(self) -> "InternalFrame":
        # Use resolved_copy to fix the natural order.
        internal = super()._internal.resolved_copy
        sdf = InternalFrame.attach_distributed_sequence_column(
            internal.spark_frame, column_name=self._sequence_col
        )
        return internal.with_new_sdf(spark_frame=sdf.orderBy(NATURAL_ORDER_COLUMN_NAME))

    @lazy_property
    def _sequence_col(self) -> str:
        # Use resolved_copy to fix the natural order.
        internal = super()._internal.resolved_copy
        return verify_temp_column_name(internal.spark_frame, "__distributed_sequence_column__")

    def _select_rows_by_series(
        self, rows_sel: "Series"
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        raise iLocIndexer._NotImplemented(
            ".iloc requires numeric slice, conditional "
            "boolean Index or a sequence of positions as int, "
            "got {}".format(type(rows_sel))
        )

    def _select_rows_by_spark_column(
        self, rows_sel: Column
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        raise iLocIndexer._NotImplemented(
            ".iloc requires numeric slice, conditional "
            "boolean Index or a sequence of positions as int, "
            "got {}".format(type(rows_sel))
        )

    def _select_rows_by_slice(
        self, rows_sel: slice
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        def verify_type(i: int) -> None:
            if not isinstance(i, int):
                raise TypeError(
                    "cannot do slice indexing with these indexers [{}] of {}".format(i, type(i))
                )

        has_negative = False
        start = rows_sel.start
        if start is not None:
            verify_type(start)
            if start == 0:
                start = None
            elif start < 0:
                has_negative = True
        stop = rows_sel.stop
        if stop is not None:
            verify_type(stop)
            if stop < 0:
                has_negative = True

        step = rows_sel.step
        if step is not None:
            verify_type(step)
            if step == 0:
                raise ValueError("slice step cannot be zero")
        else:
            step = 1

        if start is None and step == 1:
            return None, stop, None

        sdf = self._internal.spark_frame
        sequence_scol = sdf[self._sequence_col]

        if has_negative or (step < 0 and start is None):
            cnt = sdf.count()

        cond = []
        if start is not None:
            if start < 0:
                start = start + cnt
            if step >= 0:
                cond.append(sequence_scol >= SF.lit(start).cast(LongType()))
            else:
                cond.append(sequence_scol <= SF.lit(start).cast(LongType()))
        if stop is not None:
            if stop < 0:
                stop = stop + cnt
            if step >= 0:
                cond.append(sequence_scol < SF.lit(stop).cast(LongType()))
            else:
                cond.append(sequence_scol > SF.lit(stop).cast(LongType()))
        if step != 1:
            if step > 0:
                start = start or 0
            else:
                start = start or (cnt - 1)
            cond.append(((sequence_scol - start) % SF.lit(step).cast(LongType())) == SF.lit(0))

        return reduce(lambda x, y: x & y, cond), None, None

    def _select_rows_by_iterable(
        self, rows_sel: Iterable
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        sdf = self._internal.spark_frame

        if any(isinstance(key, (int, np.int64, np.int32)) and key < 0 for key in rows_sel):
            offset = sdf.count()
        else:
            offset = 0

        new_rows_sel = []
        for key in list(rows_sel):
            if not isinstance(key, (int, np.int64, np.int32)):
                raise TypeError(
                    "cannot do positional indexing with these indexers [{}] of {}".format(
                        key, type(key)
                    )
                )
            if key < 0:
                key = key + offset
            new_rows_sel.append(key)

        if len(new_rows_sel) != len(set(new_rows_sel)):
            raise NotImplementedError(
                "Duplicated row selection is not currently supported; "
                "however, normalised index was [%s]" % new_rows_sel
            )

        if len(new_rows_sel) == 0:
            cond = SF.lit(False)
        else:
            cond = sdf[self._sequence_col].isin(
                [SF.lit(int(key)).cast(LongType()) for key in new_rows_sel]
            )
        return cond, None, None

    def _select_rows_else(
        self, rows_sel: Any
    ) -> Tuple[Optional[Column], Optional[int], Optional[int]]:
        if isinstance(rows_sel, int):
            sdf = self._internal.spark_frame
            return (sdf[self._sequence_col] == rows_sel), None, 0
        elif isinstance(rows_sel, tuple):
            raise SparkPandasIndexingError("Too many indexers")
        else:
            raise iLocIndexer._NotImplemented(
                ".iloc requires numeric slice, conditional "
                "boolean Index or a sequence of positions as int, "
                "got {}".format(type(rows_sel))
            )

    def _select_cols_by_series(
        self, cols_sel: "Series", missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        raise ValueError(
            "Location based indexing can only have [integer, integer slice, "
            "listlike of integers, boolean array] types, got {}".format(cols_sel)
        )

    def _select_cols_by_spark_column(
        self, cols_sel: Column, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        raise ValueError(
            "Location based indexing can only have [integer, integer slice, "
            "listlike of integers, boolean array] types, got {}".format(cols_sel)
        )

    def _select_cols_by_slice(
        self, cols_sel: slice, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        if all(
            s is None or isinstance(s, int) for s in (cols_sel.start, cols_sel.stop, cols_sel.step)
        ):
            column_labels = self._internal.column_labels[cols_sel]
            data_spark_columns = self._internal.data_spark_columns[cols_sel]
            data_fields = self._internal.data_fields[cols_sel]
            return column_labels, data_spark_columns, data_fields, False, None
        else:
            not_none = (
                cols_sel.start
                if cols_sel.start is not None
                else cols_sel.stop
                if cols_sel.stop is not None
                else cols_sel.step
            )
            raise TypeError(
                "cannot do slice indexing with these indexers {} of {}".format(
                    not_none, type(not_none)
                )
            )

    def _select_cols_by_iterable(
        self, cols_sel: Iterable, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        if all(isinstance(s, bool) for s in cols_sel):
            cols_sel = [i for i, s in enumerate(cols_sel) if s]
        if all(isinstance(s, int) for s in cols_sel):
            column_labels = [self._internal.column_labels[s] for s in cols_sel]
            data_spark_columns = [self._internal.data_spark_columns[s] for s in cols_sel]
            data_fields = [self._internal.data_fields[s] for s in cols_sel]
            return column_labels, data_spark_columns, data_fields, False, None
        else:
            raise TypeError("cannot perform reduce with flexible type")

    def _select_cols_else(
        self, cols_sel: Any, missing_keys: Optional[List[Name]]
    ) -> Tuple[
        List[Label],
        Optional[List[Column]],
        Optional[List[InternalField]],
        bool,
        Optional[Name],
    ]:
        if isinstance(cols_sel, int):
            if cols_sel > len(self._internal.column_labels):
                raise KeyError(cols_sel)
            column_labels = [self._internal.column_labels[cols_sel]]
            data_spark_columns = [self._internal.data_spark_columns[cols_sel]]
            data_fields = [self._internal.data_fields[cols_sel]]
            return column_labels, data_spark_columns, data_fields, True, None
        else:
            raise ValueError(
                "Location based indexing can only have [integer, integer slice, "
                "listlike of integers, boolean array] types, got {}".format(cols_sel)
            )

    def __setitem__(self, key: Any, value: Any) -> None:
        if is_list_like(value) and not isinstance(value, Column):
            iloc_item = self[key]
            if not is_list_like(key) or not is_list_like(iloc_item):
                raise ValueError("setting an array element with a sequence.")
            else:
                shape_iloc_item = iloc_item.shape
                len_iloc_item = shape_iloc_item[0]
                len_value = len(value)
                if len_iloc_item != len_value:
                    if self._is_series:
                        raise ValueError(
                            "cannot set using a list-like indexer with a different length than "
                            "the value"
                        )
                    else:
                        raise ValueError(
                            "shape mismatch: value array of shape ({},) could not be broadcast "
                            "to indexing result of shape {}".format(len_value, shape_iloc_item)
                        )
        super().__setitem__(key, value)
        # Update again with resolved_copy to drop extra columns.
        self._psdf._update_internal_frame(
            self._psdf._internal.resolved_copy, requires_same_anchor=False
        )

        # Clean up implicitly cached properties to be able to reuse the indexer.
        del self._internal
        del self._sequence_col

def _test() -> None:
    import os
    import doctest
    import sys
    from pyspark.sql import SparkSession
    import pyspark.pandas.indexing

    os.chdir(os.environ["SPARK_HOME"])

    globs = pyspark.pandas.indexing.__dict__.copy()
    globs["ps"] = pyspark.pandas
    spark = (
        SparkSession.builder.master("local[4]")
        .appName("pyspark.pandas.indexing tests")
        .getOrCreate()
    )
    (failure_count, test_count) = doctest.testmod(
        pyspark.pandas.indexing,
        globs=globs,
        optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE,
    )
    spark.stop()
    if failure_count:
        sys.exit(-1)

if __name__ == "__main__":
    _test()

redpajama_set_name: RedPajamaGithub


My goal as a wedding photographer is to provide you with a beautiful visual record of your wedding day for you and your family to enjoy for years to come. It is important to me that you have the best experience possible, and a professional and unobtrusive photographer is key to your enjoyment of the day. My equipment is top of the line and my background as a software engineer gives me an edge in the technical aspects of digital photography including post processing. I look forward to working with you to make your day the best it can be and to provide you with wedding photographs that you will treasure.
Raj was amazing on the day- so friendly and flexible and made us feel really comfortable! My mother who is very picture shy was even at ease with him. He took great shots of the wedding and was very unobtrusive. The pictures were amazing- really well shot and beautifully executed- and delivered in the time frame that we agreed. I cannot recommend Raj highly enough.
Raj did a great job for our outdoor wedding. He came highly recommended (friends with the groom's brother) and we love his photojournalistic style. With Raj, you get a lot of value for a great price. I can't wait to see our photographs!


text:
The Political Economy of Government Auditing
Financial Governance and the Rule of Law in Latin America and Beyond
Carlos Santiso
Published May 31, 2016 by Routledge-Cavendish
Published July 8, 2009 by Routledge-Cavendish
The Political Economy of Government Auditing: Financial Governance and the Rule of Law in Latin America and Beyond
Book Description Table of Contents Author(s) Reviews Instructor Resources Support Material
The Political Economy of Government Auditing addresses the elusive quest for greater transparency and accountability in the management of public finances in emerging economies; and, more specifically, it examines the contribution of autonomous audit agencies (AAAs) to the fight against corruption and waste. Whilst the role of audit agencies in curbing corruption is increasingly acknowledged, there exists little comparative work on their institutional effectiveness. Addressing the performance of AAAs in emerging economies, Carlos Santiso pursues a political economy perspective that addresses the context in which audit agencies are embedded, and the governance factors that make them work or fail. Here, the cases of Argentina, Brazil and Chile are examined, as they illustrate the three – parliamentary, court and independent – models of AAAs in modern states, and their three distinct trajectories of reform, or lack of reform. Beyond Latin America, considerations on the reform of government auditing in other countries, developed and developing are also taken up as, it is argued, while institutional arrangements for government auditing matter, political factors ultimately determine the effectiveness of AAAs. Reforming AAAs, it is concluded, must consider the trajectory of state building, the role of law in public administration and the quality of governance.
An important contribution to the comparative study of governance institutions, and especially those tasked with overseeing the budget and curbing corruption, The Political Economy of Government Auditing will be of interest to scholars and students of comparative politics, development studies, administrative law, and public finance; as well as to development practitioners and policy-makers in developing countries, donor governments and international institutions.
Introduction: Budget Institutions and Financial Governance 1. Political Economy of Budget Oversight and External Auditing 2. Institutional Arrangements for External Auditing 3. The Board Model and the Case of Argentina 4. The Court Model and the Case of Brazil 5. The Monocratic Model and the Case of Chile 6. Government Auditing in Transition. Conclusions: Auditing, Accountability and Anticorruption
Carlos Santiso is Manager of the Governance section at the African Development Bank
"This book is an important contribution to our understanding of how corruption can be prevented by strengthening those institutions tasked with scrutinizing government and overseeing public finances. It provides useful lessons to reformers in Latin America in their efforts to promote integrity in the use of public resources. These lessons of experience are also relevant for African countries pursuing the same objectives. "
Dr. Donald Kaberuka, President of the African Development Bank and former Minister of Finance of Rwanda
"Controlling corruption represents a fundamental challenge for all societies in their quest to improve the lives of the most vulnerable. Carlos Santiso eloquently demonstrates the importance of strengthening the institutions of integrity to combat corruption and, in particular, enhance transparency and accountability in public finances. His analysis of the role of audit agencies will undoubtedly help reformers around the world in the fight against corruption and hopefully inspire others to further enhance our knowledge of these overlooked oversight institutions."
Dr. Peter Eigen, Founder of Transparency International (TI) and Chairman of EITI
"Carlos Santiso brings into this book a unique experience that combines top positions in governmental and financial agencies, as well as in distinguished academic positions. These varied perspectives make for a book that will be indispensable reading for everyone interested in these issues."
Guillermo O'Donnell, Helen Kellogg Professor of Government and Senior Fellow of the Kellogg Institute for International Studies, Notre Dame University
"Carlos Santiso persuasively demonstrates that institutional design shapes the relationship between agents and principals in public budgeting. His application of agency theory to the audit function is especially valuable because of the assumed independence of auditors. His framework can be applied to relationships between politicians and officials in all areas of government work to further good governance and financial integrity."
Allen Schick, Governance Fellow, Brookings Institution, and Professor of Political Science, University of Maryland, College Park
"This book fills a void in the literature, with a serious treatment of external audit institutions in Latin America, encompassing the political economy issues that impact their effectiveness. This is a must read for those interested in reforming their own public financial management system and those supporting the development of better public finance systems. The lessons are universal, and provide a firm, pragmatic foundation for moving forward and important guidance for sequencing of reforms."
William L. Dorotinsky, Lead Public Sector Specialist, the World Bank
"The book stresses in various places that, inevitably, the effectiveness of audit agencies does not depend only on organizational factors but also, importantly, on the influence of political factors. For this reason these institutions cannot be copied from other countries and cannot be created over night. They must be created over a period of time and reflect the political reality of the countries. Dr. Santiso's book is of particularly great value in this context."
Vito Tanzi, former Director of the Fiscal Affairs Department, International Monetary Fund
"With this book, Carlos Santiso breaks new ground in several areas – providing a unique, readable overview of the world of autonomous audit agencies, offering the first comparative study of their organization and operations, and simultaneously applying neo-institutional and political economy analysis to develop a theory on their impact on improving public resource management and combating corruption. The work should inspire others to consider these overlooked institutions in their own research agendas, but it will clearly remain a classic for some time."
Linn Hammergren, former Senior Public Sector Management Specialist, World Bank
"This is a fine piece of comparative analysis, combining academic research findings with policy advice on challenges that many developing countries face currently. Santiso's book is an indispensable reading for scholars and practitioners looking for an inspiring read on a subject that otherwise finds itself enclosed in arcane technical literature."
Dr. Bruno Speck, Senior Advisor for Latin America, Transparency International
This book is included in the following series:
Law, Development and Globalization
Socio-Legal Studies - International Law & Politics
Public Administration & Management
Socio-Legal Studies

redpajama_set_name: RedPajamaCommonCrawl


Official music video for reggae artiste Jesse Royal's "Gimmie Likkle" and "Finally".
Wellington R Burt Will ..After 92 years, millionaire miser's heirs finally split $100M .
LIKE & SUBSCRIBE TO OUR CHANNEL FOR SEASON 2 COMING OUT SOON!
Benje - Happy Birthday / Jewels of Desire (Official Music Video) "2018 Soca"
Official music video for "Living It Up" by Damian "Jr. Gong" Marley, off the Stony Hill album.


I often get asked "where did you get that big bag of coconut flour". Tropical Traditions is one of the best quality sources of coconut oil and coconut flour I have found. There is also some variability in coconut flours as some brands don't soak up as much moisture as others (some people had problems with my cinnamon rolls because of this). This is the brand I use so you won't have any issues like that with any of my recipes if you use this brand. Also if you purchase from the links below and are a new customer I get a little gift certificate which helps me pay for ingredients for all my experimentation (it took me over 10 pounds of almond flour to get my sub bread right!).
They also have a deal going on where new customers will receive a free copy of their Virgin Coconut Oil book (a $25 value). Thanks for your support!
Preheat the oven to 300 degrees F. In a medium-sized bowl, stir together the almond or coconut flour, psyllium husks, baking powder, and salt. Add the eggs and vinegar. Stir continuously as you add the hot marinara or water. Combine until very smooth. Place the dough onto a piece of greased parchment paper (I used THIS coconut oil spray). Using a rolling pin, roll the dough out in a circle shape with even thickness throughout. Place brie in the center, and fold pastry around it, sealing seams. Transfer to baking sheet, seam side down. Bake brie until pastry is golden, 23-35 minutes.
Drizzle with Nature's Hollow Honey. Sprinkle with pecans. Serve with "healthified" cheez-it crackers. Makes 8 servings.
This will be fun to have available in the holiday season this year. We did brie en croute for years and still serve it for guests, with plain warmmed brie for ourselves. This will be a fun twist for us to have on hand.
Hi Maria, I have to report all I have recreated from your site has been a fantastic success. Thank, thank, thank you for helping me find a way to bake my cakes and eat them too! However, my sweet little kiddies have requested to have a "normal" colored bun in their lunch boxes (purple must not be "in" this year). I know that you mentioned Jay Robb psyllium husks are the magic brand for appropriately colored breads, but I can only locate the powder and it looks like you grind your own. Can you tell me if there are other brands that you have tried that work, or if both of the Jay Robb versions turn out okay for you? Also, my youngest loves the oatmeal recipe and wants it for dinner and breakfast some days and now I am worried about how much psyllium is too much for the toddlers?
On your Amazon page, you recommend Coconut Secret. Is it similar enough to Tropical Traditions coconut flour that you don't have to worry about absorbency? I'm limited to what I can order online but can order the Coconut Secret one.
I cannot at all digest psyllium. therfore i stoppped making your recipes, which i am sooo sad about.
please please can you find alternatives!!!!?
I love all your recipes but most all have psyllium in them and psyllium is what holds the breads together.
help! ALSO, ARE you going to update your muffin recipe the pumpkin mini muffins?
I used Maria's hot cereal recipes to slowly increase our psyllium before trying her bread recipes and that worked great! Every time I made a batch, I added a little more psyllium so you can start off with only a tiny bit and work up from there. IT is worth it!
This will work in your favor then because I already planned on buying several gallons of coconut oil, flour, cream, shreds and butter from them on weds. I am glad you posted this today so you can get credit for it!
Just ordered from Tropical Traditions. They have a great sale going on right now and shipping wasn't bad.
We go through Coconut Flour and Oil like crazy. I find this humorous because a year ago I would have told you that I hate coconut…. I usually buy Coconut Secret flour–how does that one compare? I ask because I did have cinnamon roll issues….
I just made the calzone with this recipe after watching the video you have. It was fantastic! It's amazing watching the evolution of Healthy bread in your books and blog over the past year. Keep it up and I can't wait to see what you create next.
YES!!! I so wanted the baked brie makeover. This is fantastic.
I have to fess up…I made baked brie with frozen pastry dough this weekend. Not once, but twice! While the crisp golden outside makes a lovely presentation, it really isn't my favorite part…I want the cheese! I wonder if I couldn't just spread a round of brie with some no-sugar apricot jam, sprinkle with cranberries, and bake it in a small, covered ramekin until gooey?
I have been baking brie that way for years. The puff pastry does nothing for me so I always bake the round with Nature's Hollow Jam and pecans and it comes out delicious.
I used the pastry recipe for making buns and pizza crust. It worked wonderfully for both.
Maria, awesome site! Thanks for your help on my low-carb journey.
I'm taking a ratio based approach. How many grams is your 1 1/4 cup of Almond Flour? Just curious. My measurement is about 155 grams.
So when shopping for psyllium husk (not powder), just go for quality (i.e. organic, etc.)? As my brands differ from yours. What do you grind your husks in?
Can I use ground chis seeds instead of psyllium husk? I know it sais no substitutions but has anyone tried it? Maybe double the boiled water?
Made a spin on this baked brie for Thanksgiving….I "healthified" cranberries…1 cup cranberries, 1 cup water and 1/2 swerve and a dash of orange peel. I cooked them until most of the berries "popped" and took it off the burner to cool…I added the cooked cranberries to the top of the brie then folded your pastry around it per the recipe above….Once baked, I added the pecans and honey to the top and served…it was beautiful and delicious! Thank you for your awesome recipe!
So, I tried this recipe and I'm embarrassed to say that it turned a blackish purple.. its not burnt. It's just off color. Help! What did I do wrong??
I love this recipe. it was delicious. I will be making this again, and often.
Is there a specific reason you can't use the whole egg instead of just egg whites?
Must report, was disappointed with this recipe.
Had to bake WAY longer to get it golden than instructed. When I pulled it out and cut it open not only was the cheese completely melted, but also the dough was completely uncooked, wet and spongy. Very strange.
Also experienced the purple color on the inside, which I see is the fault of the NOW brand husk powder that I used.
IDK if it was user error or just not as good ingredients, but I really wish that it worked well for me like some others above.
Have you found there to be a big difference between coconut secret and tropical traditions coconut flour compared to bob's red mill coconut flour? I have only used bob's red mill.
Hey Maria, For this recipe, which do you prefer to use.. the almond flour or coconut flour? I've tried both, but end up with almost hollow buns. Also can whole eggs be used and if so, how many would you suggest? Thank you so much for all you do for us.
Fat causes the dough to not rise as well. I don't recommend whole eggs.
Hi Maria, this looks incredible. I have included it in my Best Low Carb Christmas Leftover Recipes roundup as it would be a great way to utilise all that leftover cheese (not that I can ever imagine that happening in our house). Take care, Libby.


For the first time since its original release, the 2005 opus "This godless endeavor", is being released on vinyl! A true milestone in Century Media Records' and NEVERMORE's history, on time with the label's 30th anniversary in 2018, this highly sought after album returns again on vinyl! Mastered for vinyl by Patrick W. Engel (ICED EARTH, TIAMAT, GRAVE). The album comes on two 180 gram vinyls with an etching on Side D and contains a huge poster as well as the CD as extra.


Can you be liable for texting someone while they are driving if they cause an accident as a result of your text ?
I recently read about a very interesting case that relates to texting and driving. An accident in New Jersey which caused very serious injuries was the result of distracted driving; more specifically texting and driving. The question that was put to the courts was whether or not a remote texter can be held liable for texting someone else while they were driving and that driver causes an accident. Before I start, let me clarify again that this accident took place in the United States of America and the laws are very different than Canadian laws and the laws in Ontario.
The New Jersey court deemed that the person who sends the text can only be help responsible if they knew their text was being viewed by the recipient while they driving. In the case they presented they concluded that there was insufficient evidence that the person who sent the text would have known well enough that the text she sent to her friend was going to be responded to while he was driving. The court ruled that the "texter" could not be help liable due to insufficient knowledge and the motion was defeated. An accident that caused serious injury to two motorcyclists occurred within less than 30 seconds of when the drover's phone records showed that he received a text from the texter.
To paraphrase, in a nutshell, it was decided that someone sending text messages has a duty not to text someone who is driving if the texter knows, or has reason to know that the recipient will view the text as they are driving. In this case, there was insufficient evidence to prove that the "texter" had such knowledge when she texted the driver. The courts stated that she did not actively encourage the driver to text her while driving and that their relationship was not close enough to have known how the driver would have responded upon receiving her text. The court also determined that the act of sending a text message is not actively encouraging someone to immediately read the text or respond. To read more about this case, visit the ABA Journal.


Tonight the last one at the Duke University, Durham!
Artemis Quartett shared a link ? in Schenectady, New York.
Artemis Quartett updated their profile picture.
Artemis Quartett shared a link ? in Pittsburgh, Pennsylvania.


text:
using System;
using Rainbow.Framework.Security;
using Rainbow.Framework.Web.UI;

namespace Rainbow.Admin
{
    /// <summary>
    /// The Logoff page is responsible for signing out a user
    /// from the cookie authentication, and then redirecting
    /// the user back to the portal home page.
    /// This page is executed when the user	clicks
    /// the Logoff button at the top of the page.
    /// </summary>
    public partial class Logoff : Page
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            // Signout
            PortalSecurity.SignOut();
        }

        #region Web Form Designer generated code

        /// <summary>
        /// Raises the Init event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            this.Load += new EventHandler(this.Page_Load);
            base.OnInit(e);
        }

        #endregion
    }
}


I bought a new pair of Frye Carson shortie's in burnt red & conditioned them with Apple conditioner instead of the Frye conditioner because the Frye turns them darker. I then sprayed 2 coats of Apple Garde Rain & Stain repellant, allowing each coat to dry. Tonight I wore them for the second time. It isn't even raining but I think my doormat was dewy. When I wiped my feet I got water spots on the boots. I rubbed them with my fingers & it has been about 2 hours & they haven't dried out. They are tiny but it is still frustrating. Now I'm worried about all my purses I thought were protected with these products and upset about my boots. It won't work to apply the Frye conditioner now. It will make my boots darker but it won't get rid of the stain because I already stained my tan Frye Carson then applied the Frye conditioner hoping to hide the stain but it didn't.
The only thing I can think of is to take them to a cobbler. Seems weird that happened to you -- I've gotten water spots on my Fryes that dry right up, even without being treated!
It depends on the leather & the color. I've read about it before & it's happened to me before so I treated them this time. I guess I'm going to have to use the Frye conditioner & accept them getting darker so at least they will be darker all over instead of in spots. The existing spots wont blend in though because I've been through this before. It's been 12 hours now & they are still there. Tiny but annoying to me. I don't know if the Frye conditioner will be able to soak through the apple garde rain & stain repellant but I guess if the water did it might. I'm really worried about my purses now, especially my Coach Classic Patricia in British Tan. The Coachies love apple garde though.
Hell If I can only wear boots in the Summer what do I wear all winter? Only my black ones. Boring. And it doesn't have to be wet weather for it to happen. I got the spot on the tan ones from washing my hands the first day I wore them.
no offense intended but aren't Frye boots kind of a rustic/boho kind of look so that marks and spots aren't really that disastrous?
Scuffs are one thing but water spots look like I'm a drunk who spills drinks on myself or a guy who drips pee on his feet.
I have top one, Carson boots, and I don't know what to do with the stains. I got into rain once and tried to clean them without any success. Advice?
This is the kind of stain where you can fight water with water.
Take a clean white cloth, wet it with room temperature water, then squeeze it out. Use the damp cloth to apply water to the whole stain and beyond, leaving less water as you move away from the stain. The ring should become weaker, and you can gently stroke and blot the area to distribute the color fairly evenly.
Let it dry, (repeat if you want to work on it more), and apply conditioner once you're satisfied with the results.
I once took out a very noticeable water stain from a deerskin bag this way. I can barely perceive it now, even examining the area where I know it existed.
Hopefully this method can work for you. Good luck!
Ive used the same method above too on a purse. I also took a hair dryer and lightly dried it.....it worked!
I can't offer any but it looks like others have. Let me know if it works for you. I'm not sure if it is too late for me as I have treated over the stain on my tan ones with frye conditioner so I may have sealed the stain in & prevent the water trick from working.
where did you buy Frye's conditioner? I looked around and could not find any. Thanks!


text:
Christ. Culture. Church. Community.
Published on October 5, 2016 / ucnwp-admin
The Dangers of Physician-Assisted Death
D.C. Council member Mary M. Cheh (D-Ward 3) introduces the "Death With Dignity Act of 2015." (Lawler Duggan for The Washington Post)
Politicians in the nation's capital will vote this week on a physician-assisted death bill, a measure that cuts to the core of human nature, dignity and civilization.
If it passes, the bill would allow a competent adult patient who has been diagnosed with an illness that will be fatal within six months (who is not under readily identifiable coercion and is not clinically depressed) to request and receive a prescription from a licensed D.C. physician and D.C. pharmacist to end the patient's life.
The D.C. Death With Dignity Act of 2015 is patterned after a 1997 law in Oregon, and, buoyed by the recent passage of a similar measure in California, the bill's proponents are confident that it will pass.
The proposed legislation, which enjoyed the endorsement of The Washington Post's editorial board, is slated to go to committee vote Wednesday. If the legislation is approved by a majority committee vote, the council is expected to vote on it as a whole in the weeks ahead.
As a doctor and as a theologian, the ethical dimensions of this bill must be considered in light of medical practice, as well as more foundational beliefs about the nature and value of human dignity.
The most vocal proponents of the bill include the patients' rights advocacy group Compassion and Choices. The group has called for a formal structuring of an aid-in-dying practice guideline as part of a program they see as nationally desirable and inevitable, despite the medical establishment's long-standing opposition to the practice.
The group's agenda centers on the patient's right of autonomy as the sole determinant of action and on the assumption that dying patients have inadequate choices available to them as they prepare for death.
But the proposed legislation is fundamentally flawed and out of touch with normative ethical medical and public-policy decisions.
Advocates suggest that dying patients don't really have a "choice," an idea that is simply uninformed. In fact, programs already exist for the terminally ill in the form of hospice, palliative care and intensive care — all of which provide excellent care, and prevention and alleviation of suffering.
SOURCE: The Washington Post
Allen Roberts and Scott Redd
Posted in Diseases and Conditions, HealthTagged California, civilization, D.C., D.C. Death With Dignity Act, D.C. Death With Dignity Act of 2015, dignity, human dignity, human nature, Oregon, physician-assisted death bill
Abortion Comes Up at Tim Kaine, Mike Pence Vice-Presidential Debate
Study Reveals the State of Youth Ministry In the United States
Watch/Listen LIVE on Gospel Light Society, Gospel Light House of Prayer, Go To Church Online, Periscope, Periscope @glsociety, Facebook Live, Roku, Apple TV, Chromecast, and Spreaker.
After preaching the Gospel every day for 367 days straight throughout the 2016 presidential campaign season, Daniel Whyte III is preaching the Gospel for 1,000 days during the Trump presidency. If you think a new president being in office is the only thing needed to save America and 'make America great again,' you are woefully deceived. The church must follow through and "keep the main thing the main thing: and that is reaching unbelievers with the Gospel of the Lord Jesus Christ and praying for their salvation, for the problem in America is not only disobedient presidents, politicians, and people, but disobedient pastors, preachers, and parishioners who have refused to obey the Lord's Great Commission which is to, 'Go ye into all the world, and preach the gospel to every creature,' and who have refused to obey God's repeated commands to 'pray without ceasing' for unbelievers, believers, and political leaders." So, we encourage you to pray for the new president, but not to get caught up in the political happenings like the world does. Nothing much is going to change until people get saved and get their hearts right with the Lord. And that is what this campaign is all about.
• Click here to view 2016 mission statement for the Just Jesus Evangelistic Campaign.
• Click here to view all previous messages in the Just Jesus Evangelistic Campaign.
• Click here to view all previous messages in the Revive the Family, Revive the Church, Awaken the Nation series.
GLORY BE TO GOD! By the grace of God, over the past 40 years, Daniel Whyte III has preached the Gospel over 6,000 times to over 4 million people in over 25 countries personally, and nearly every country of the world online. In addition, Gospel Light Society International and GLM Omnimedia Group LLC have a network of over 1,000 Christian news sites which contain the preaching of the Gospel and Christian discipleship teaching in every country of the world and in every major city of the world. BCNN1 is a part of that network. Please click here to view some of those sites.
Gospel Light Society Podcasts
Gospel Light Society and GLM Omnimedia Group LLC have Christian news sites which contain the preaching of the Gospel and Christian discipleship teaching in every country of the world and in every major city of the world. Click here to view those sites.


text:
Q: TCP data rec timeout don't work for me I have a boost async tcp client that need recevive data from server all time.
I want put there a time out that when don't arive data for n sec disconnect from server and try againg to connect.
and I use vc++.
  void tcpclient::Connect(){
    .....
    socket_.async_connect(*iterator,boost::bind(&tcpclient::AfterConnection,shared_from_this(),boost::asio::placeholders::error));
  }

  void tcpclient::AfterConnection(const boost::system::error_code& error){
        if (!error)
        {
           SetTimeout();
        }
  }

  void tcpclient::SetTimeout(int sec = 1)
  {

    SOCKET native_sock = socket_.native();
    int result = SOCKET_ERROR;
    if (INVALID_SOCKET != native_sock)
    {
      struct timeval tv;
      tv.tv_sec = sec;
      tv.tv_usec = 0;
      result = setsockopt(native_sock, SOL_SOCKET, SO_RCVTIMEO,(char *)&tv,sizeof(struct timeval));
      i = GetLastError();

    }

  }

and I read like blow:
        socket_.async_receive(boost::asio::buffer(buffer, 1024),
            boost::bind(&tcpClient::handleReceive,
            shared_from_this(),
            boost::asio::placeholders::error,
            buffer,
            boost::asio::placeholders::bytes_transferred)
            );

but when I try to simulate case that don't arive data connection stay etablished:
$netstat -ao
TCP    192.168.0.6:62836      192.168.0.5:telnet     ESTABLISHED     2840
what is the problem why this happend?

A: Setting SO_RCVTIMEO causes otherwise-blocking calls to read to return with no data after waiting for the specified time, as a non-blocking socket would have done immediately.
So, the question is, what do you, or Boost, do when read returns an EWOULDBLOCK error? You need to show how you're doing the read; if Boost is handling it in an event loop (based on select or poll) it probably just waits for some data to become available.
If that's the case, a better approach is to register a timer callback with the event loop to fire every second or however often, and check whether you received some data during the previous second. The socket options won't help you with that.

redpajama_set_name: RedPajamaStackExchange


Added a favorites feature! Simply hold down on a sound effect button for around 5 seconds to mark it as a favorite. If you hold down on that button again for around 5 seconds it will be unmarked. Now you'll be able to easily remember which sounds you like the most.
Added new backgrounds. Some of the previous ones weren't retro enough.
Word Owl's Wordsearch: Kindergarten Edition is now available on the Apple iOS App Store for iPad! I was previously unable to release this app on Apple due to an issue with iOS 7, but that issue has been resolved so now it's available.
Word Owl's WordSearch is a neat, big, and colorful word search for children. This Kindergarten Edition of Word Owl's Wordsearch features over 100 sight words for children in or around Kindergarten. These words have been gathered from numerous sight word lists provided by real Kindergarten classes in different schools. Help your kid learn and retain several words while having fun!