# Path: calliope/exceptions.py
# def _formatwarning(message, category, filename, lineno, line=None):
# def warn(message, _class=ModelWarning):
# def print_warnings_and_raise_errors(warnings=None, errors=None):
# class ModelError(Exception):
# class BackendError(Exception):
# class ModelWarning(Warning):
# class BackendWarning(Warning):
# 
# Path: calliope/time/clustering.py
# def _stack_data(data, dates, times):
# def reshape_for_clustering(data, loc_techs=None, variables=None):
# def get_mean_from_clusters(data, clusters, timesteps_per_day):
# def find_nearest_vector_index(array, value, metric="rmse"):
# def get_closest_days_from_clusters(data, mean_data, clusters, daily_timesteps):
# def _timesteps_from_daily_index(idx, daily_timesteps):
# def map_clusters_to_data(
#     data, clusters, how, daily_timesteps, storage_inter_cluster=True
# ):
# def get_clusters(
#     data,
#     func,
#     timesteps_per_day,
#     tech=None,
#     timesteps=None,
#     k=None,
#     variables=None,
#     **kwargs,
# ):
# def hartigan_n_clusters(X, threshold=10):
#     def _H_rule(inertia, inertia_plus_one, n_clusters, len_input):
#     X = np.nan_to_num(reshaped_data, nan=0.0, posinf=0.0, neginf=0.0)
#     X = reshape_for_clustering(data, tech, variables)
#     HK = threshold + 1
#         HK = _H_rule(inertia, inertia_plus_one, n_clusters, len_input)


import logging
import datetime
import numpy as np
import pandas as pd
import xarray as xr
from calliope import exceptions
from calliope.time import clustering
            raise exceptions.ModelError(
                "No time clustering column given, but multiple columns found in "
                "{0}. Choose one column and add it to {1} as {1}:name_of_column.".format(
                    file, clustering_func
                )
            )
        elif isinstance(df, pd.DataFrame) and column not in df.columns:
            raise KeyError(
                "time clustering column {} not found in {}.".format(column, file)
            )
        elif isinstance(df, pd.DataFrame):
            clusters = (
                df.loc[:, column].dropna().groupby(pd.Grouper(freq="1D")).unique()
            )

        # Check there weren't instances of more than one cluster assigned to a day
        # or days with no information assigned
        if any([len(i) == 0 for i in clusters.values]):
            raise exceptions.ModelError(
                "Missing cluster days in `{}:{}`.".format(file, column)
            )
        elif any([len(i) > 1 for i in clusters.values]):
            raise exceptions.ModelError(
                "More than one cluster value assigned to a day in `{}:{}`. "
                "Unique clusters per day: {}".format(file, column, clusters)
            )
        else:
            clusters.loc[:] = [i[0] for i in clusters.values]

    else:

# Path: calliope/exceptions.py
# def _formatwarning(message, category, filename, lineno, line=None):
# def warn(message, _class=ModelWarning):
# def print_warnings_and_raise_errors(warnings=None, errors=None):
# class ModelError(Exception):
# class BackendError(Exception):
# class ModelWarning(Warning):
# class BackendWarning(Warning):
# 
# Path: calliope/time/clustering.py
# def _stack_data(data, dates, times):
# def reshape_for_clustering(data, loc_techs=None, variables=None):
# def get_mean_from_clusters(data, clusters, timesteps_per_day):
# def find_nearest_vector_index(array, value, metric="rmse"):
# def get_closest_days_from_clusters(data, mean_data, clusters, daily_timesteps):
# def _timesteps_from_daily_index(idx, daily_timesteps):
# def map_clusters_to_data(
#     data, clusters, how, daily_timesteps, storage_inter_cluster=True
# ):
# def get_clusters(
#     data,
#     func,
#     timesteps_per_day,
#     tech=None,
#     timesteps=None,
#     k=None,
#     variables=None,
#     **kwargs,
# ):
# def hartigan_n_clusters(X, threshold=10):
#     def _H_rule(inertia, inertia_plus_one, n_clusters, len_input):
#     X = np.nan_to_num(reshaped_data, nan=0.0, posinf=0.0, neginf=0.0)
#     X = reshape_for_clustering(data, tech, variables)
#     HK = threshold + 1
#         HK = _H_rule(inertia, inertia_plus_one, n_clusters, len_input)


# Path: calliope/time/funcs.py
import logging
import datetime
import numpy as np
import pandas as pd
import xarray as xr
from calliope import exceptions
from calliope.time import clustering

            raise exceptions.ModelError(
                "No time clustering column given, but multiple columns found in "
                "{0}. Choose one column and add it to {1} as {1}:name_of_column.".format(
                    file, clustering_func
                )
            )
        elif isinstance(df, pd.DataFrame) and column not in df.columns:
            raise KeyError(
                "time clustering column {} not found in {}.".format(column, file)
            )
        elif isinstance(df, pd.DataFrame):
            clusters = (
                df.loc[:, column].dropna().groupby(pd.Grouper(freq="1D")).unique()
            )

        # Check there weren't instances of more than one cluster assigned to a day
        # or days with no information assigned
        if any([len(i) == 0 for i in clusters.values]):
            raise exceptions.ModelError(
                "Missing cluster days in `{}:{}`.".format(file, column)
            )
        elif any([len(i) > 1 for i in clusters.values]):
            raise exceptions.ModelError(
                "More than one cluster value assigned to a day in `{}:{}`. "
                "Unique clusters per day: {}".format(file, column, clusters)
            )
        else:
            clusters.loc[:] = [i[0] for i in clusters.values]

    else:

        result = clustering.get_clusters(