> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# cast

> Interprets and changes a column's data to another (semantic) type. 

This has two consequences:

1. It will allow the resulting column to be used by steps only accepting the new type,
   e.g. when casting a column of concatenated texts to the `"url"` type, so that it may be used
   where Urls are expected (e.g. the step `fetch_url_content`).
2. It will change any values not conformant with the new type to the missing value (NaN). E.g.,
   casting a column of mixed data containing numbers to the `"number"` type, will replace all
   values that cannot be read as numbers with NaN.

Note that for each possible type a column can be cast to (via the `"type"` parameter, e.g. `"number"`,
`"category"` etc.), the steps accepts different configuration parameters. See the subsections under
[Parameters](#parameters) below for further details.

## Usage

The following examples show how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      E.g. to simply convert a `text` column to a `category` column, use:

      ```stan theme={null}
      cast(ds.text, {"type": "category"}) -> (ds.new_cat)
      ```
    </Tab>

    <Tab title="Example 2">
      To cast custom labels to the `sex` type, use `parse_labels` to map raw values to `female` and `male`:

      ```stan theme={null}
      cast(ds.gender_text, {
        "type": "sex",
        "parse_labels": { "female": "woman", "male": "man" }
      }) -> (ds.gender)
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      cast(input: column, {
          "param": value,
          ...
      }) -> (output: column)
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="input" type="column" required>
    The column you wish to cast.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="output" type="column" required>
    A new column with original data cast to the desired type.
  </ParamField>
</Accordion>

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <Tabs>
    <Tab title="number">
      <ParamField path="type" type="string" default="number">
        Desired semantic type of the converted data.
        Make data numerical with `"type": "number"`.
      </ParamField>

      <ParamField path="decimal" type="string" default=".">
        Separator to mark the decimal part.
        Use "." or "," to indicate how decimal values are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the thousands separator. E.g. `"decimal": "."` assumes that the period "." is used to
        separate decimals and "," thousands, as in the number string "12,173.12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>

      <ParamField path="thousand" type="string" default=",">
        Separator to mark the thousands.
        Use "." or "," to indicate how thousands are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the decimal separator. E.g. `"thousand": "."` assumes that the period "." is used to
        separate thousands and "," decimals, as in the number string "12.173,12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>
    </Tab>

    <Tab title="list[number]">
      <ParamField path="type" type="string" default="list[number]">
        Desired semantic type of the converted data.
        Make data numerical with `"type": "list[number]"`.
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>

      <ParamField path="decimal" type="string" default=".">
        Separator to mark the decimal part.
        Use "." or "," to indicate how decimal values are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the thousands separator. E.g. `"decimal": "."` assumes that the period "." is used to
        separate decimals and "," thousands, as in the number string "12,173.12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>

      <ParamField path="thousand" type="string" default=",">
        Separator to mark the thousands.
        Use "." or "," to indicate how thousands are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the decimal separator. E.g. `"thousand": "."` assumes that the period "." is used to
        separate thousands and "," decimals, as in the number string "12.173,12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>
    </Tab>

    <Tab title="currency">
      <ParamField path="type" type="string" default="currency">
        Desired semantic type of the converted data.
        Make data a currency with `"type": "currency"`.
      </ParamField>

      <ParamField path="decimal" type="string" default=".">
        Separator to mark the decimal part.
        Use "." or "," to indicate how decimal values are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the thousands separator. E.g. `"decimal": "."` assumes that the period "." is used to
        separate decimals and "," thousands, as in the number string "12,173.12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>

      <ParamField path="thousand" type="string" default=",">
        Separator to mark the thousands.
        Use "." or "," to indicate how thousands are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the decimal separator. E.g. `"thousand": "."` assumes that the period "." is used to
        separate thousands and "," decimals, as in the number string "12.173,12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>
    </Tab>

    <Tab title="list[currency]">
      <ParamField path="type" type="string" default="list[currency]">
        Desired semantic type of the converted data.
        Make data a currency with `"type": "list[currency]"`.
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>

      <ParamField path="decimal" type="string" default=".">
        Separator to mark the decimal part.
        Use "." or "," to indicate how decimal values are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the thousands separator. E.g. `"decimal": "."` assumes that the period "." is used to
        separate decimals and "," thousands, as in the number string "12,173.12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>

      <ParamField path="thousand" type="string" default=",">
        Separator to mark the thousands.
        Use "." or "," to indicate how thousands are separated when parsing text strings
        into numerical format. It is automatically assumed that the other character is used as
        the decimal separator. E.g. `"thousand": "."` assumes that the period "." is used to
        separate thousands and "," decimals, as in the number string "12.173,12".

        Values must be one of the following:

        * `.`
        * `,`
      </ParamField>
    </Tab>

    <Tab title="date">
      <ParamField path="type" type="string" default="date">
        Desired semantic type of the converted data.
        Convert data to the Date type with `"type": "date"`. This will allow e.g. the extraction of particular
        components of the date, like year, month, or day of week (with `extract_date_components`), the calculation of
        elapsed time since a given date (`time_interval`), as well as enable the use of the Trends section in graphext's
        interface.
      </ParamField>

      <ParamField path="format" type="string">
        Format to parse date strings.
        When input data contains strings (dates in text format), indicate how these strings are constructed.
        E.g. if dates are in the format "21/07/2020", use `"format": “%d/%m/%Y”` to indicate the day, month, year order and
        the use of "/" as the separator of date components. For more details on how to indicate the different
        components of the date format see e.g. [Python's strftime](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes).
      </ParamField>

      <ParamField path="unit" type="string">
        Unit of timestamp data.
        When input data is numeric, indicates whether the numbers correspond to seconds, milliseconds, microseconds
        or nanoseconds. Dates will be interpreted as so many elapsed units since the origin
        (see `origin` parameter below).

        For example, with `"unit": "ms"` and `"origin": "unix"` (the default), this would calculate the date
        corresponding to x milliseconds since 01/01/1970, where x denotes the input numbers.

        Values must be one of the following:

        * `D`
        * `s`
        * `ms`
        * `us`
        * `ns`
      </ParamField>
    </Tab>

    <Tab title="list[date]">
      <ParamField path="type" type="string" default="list[date]">
        Desired semantic type of the converted data.
        Convert data to the Date type with `"type": "date"`. This will allow e.g. the extraction of particular
        components of the date, like year, month, or day of week (with `extract_date_components`), the calculation of
        elapsed time since a given date (`time_interval`), as well as enable the use of the Trends section in graphext's
        interface.
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>

      <ParamField path="format" type="string">
        Format to parse date strings.
        When input data contains strings (dates in text format), indicate how these strings are constructed.
        E.g. if dates are in the format "21/07/2020", use `"format": “%d/%m/%Y”` to indicate the day, month, year order and
        the use of "/" as the separator of date components. For more details on how to indicate the different
        components of the date format see e.g. [Python's strftime](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes).
      </ParamField>

      <ParamField path="unit" type="string">
        Unit of timestamp data.
        When input data is numeric, indicates whether the numbers correspond to seconds, milliseconds, microseconds
        or nanoseconds. Dates will be interpreted as so many elapsed units since the origin
        (see `origin` parameter below).

        For example, with `"unit": "ms"` and `"origin": "unix"` (the default), this would calculate the date
        corresponding to x milliseconds since 01/01/1970, where x denotes the input numbers.

        Values must be one of the following:

        * `D`
        * `s`
        * `ms`
        * `us`
        * `ns`
      </ParamField>
    </Tab>

    <Tab title="text">
      <ParamField path="type" type="string" default="text">
        Desired semantic type of the converted data.
        Convert data to the Text type with `"type": "text"`. This allows the resulting column to
        be used e.g. in steps involving natural language processing (NLP).
      </ParamField>
    </Tab>

    <Tab title="category">
      <ParamField path="type" type="string" default="category">
        Desired semantic type of the converted data.
        Convert data to the Category type with `"type": "category"`. This will influence how the
        column is presented in graphext's interface, and enables the use of steps like `trim_frequencies`,
        `merge_categories` etc. When converting from `list[category]`, elements will be joined using
        the specified separator.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings and join elements.
        Which separator to use to join elements when converting from list\[category] to category.
        Note that spaces will always be stripped from individual elements.
      </ParamField>
    </Tab>

    <Tab title="list[category]">
      <ParamField path="type" type="string" default="list[category]">
        Desired semantic type of the converted data.
        Convert data to the Category type with `"type": "list[category]"`. This will influence how the
        column is presented in graphext's interface, and enables the use of steps like `trim_frequencies`, `merge_categories` etc.
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>
    </Tab>

    <Tab title="url">
      <ParamField path="type" type="string" default="url">
        Desired semantic type of the converted data.
        Convert data to the Url type with `"type": "url"`. This will allow e.g. fetching of any textual
        content found at the specified Url (with `fetch_url_content`), or linking of a network node
        in the interface to the given website (`configure_node_url`).
      </ParamField>
    </Tab>

    <Tab title="list[url]">
      <ParamField path="type" type="string" default="list[url]">
        Desired semantic type of the converted data.
        Convert data to the Url type with `"type": "list[url]"`.
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>
    </Tab>

    <Tab title="sex">
      <ParamField path="type" type="string" default="sex">
        Desired semantic type of the converted data.
        Convert data to the Sex type with `"type": "sex"`. This is essentially a categorical type
        with two predefined values for `male` and `female`. Use `parse_labels` to configure how
        raw input values should be interpreted as `female` or `male`.
      </ParamField>

      <ParamField path="parse_labels" type="object" default="{'female': 'female', 'male': 'male'}">
        Mapping of raw values to female and male categories.
        An object of the form `{"female": "female_value", "male": "male_value"}` that tells the parser
        which raw values in the input data should be interpreted as `female` and as `male`.
        For example, `{"female": "woman", "male": "man"}` will parse `woman` as `female` and `man` as `male`.

        <Accordion title="Properties">
          <ParamField path="female" type="string" default="female">
            Raw value to parse as female.
          </ParamField>

          <ParamField path="male" type="string" default="male">
            Raw value to parse as male.
          </ParamField>
        </Accordion>
      </ParamField>
    </Tab>

    <Tab title="list[sex]">
      <ParamField path="type" type="string" default="list[sex]">
        Desired semantic type of the converted data.
        Convert data to the Sex type with `"type": "list[sex]"`.
        Use `parse_labels` to configure how raw input values are interpreted.
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>

      <ParamField path="parse_labels" type="object" default="{'female': 'female', 'male': 'male'}">
        Mapping of raw values to female and male categories.
        An object of the form `{"female": "female_value", "male": "male_value"}` that tells the parser
        which raw values in the input data should be interpreted as `female` and as `male`.
        For example, `{"female": "woman", "male": "man"}` will parse `woman` as `female` and `man` as `male`.

        <Accordion title="Properties">
          <ParamField path="female" type="string" default="female">
            Raw value to parse as female.
          </ParamField>

          <ParamField path="male" type="string" default="male">
            Raw value to parse as male.
          </ParamField>
        </Accordion>
      </ParamField>
    </Tab>

    <Tab title="boolean">
      <ParamField path="type" type="string" default="boolean">
        Desired semantic type of the converted data.
        Convert data to the Boolean (logical) type with `"type": "boolean"`. If the input data is numeric,
        0s will be treated as False and all other values as True. If the input data contains text strings,
        the values {"t", "true", "yes", "y", "si", "sí", "s", "1", "1.0"} in lower- or uppercase will be interpreted as True, and the
        values {"f", "false", "no", "n", "0", "0.0"} as False. Any remaining values will be converted to NaN (missing).
      </ParamField>
    </Tab>

    <Tab title="list[boolean]">
      <ParamField path="type" type="string" default="list[boolean]">
        Desired semantic type of the converted data.
        Convert data to the Boolean (logical) type with `"type": "list[boolean]"`. If the input data is numeric, 0s will be treated as False and all other values as True. If the input data contains text strings, the values {"t", "true", "yes", "y", "si", "sí", "s", "1", "1.0"} in lower- or uppercase will be interpreted as True, and the values {"f", "false", "no", "n", "0", "0.0"} as False. Any remaining values will be converted to NaN (missing).
      </ParamField>

      <ParamField path="brackets" type="[string, null]">
        A 2-character string identifying the opening and closing brackets used to identify list strings.
        For example  "\[]", "()", "{}" etc. If `null`, any possible bracket characters at the beginning and end of a
        string will be removed before parsing the elements.
      </ParamField>

      <ParamField path="separator" type="string" default=",">
        Separation character for split strings.
        Which separation character to use to split input string into list elements.
        Note that spaces will always be stripped from individual elements.
      </ParamField>
    </Tab>
  </Tabs>
</Accordion>
