# Path: formulaic/errors.py
# class DataMismatchWarning(FormulaicWarning):
#     pass
# 
# Path: formulaic/transforms/scale.py
# @stateful_transform
# def scale(data, center=True, scale=True, ddof=1, _state=None):
# 
#     data = numpy.array(data)
# 
#     if "ddof" not in _state:
#         _state["ddof"] = ddof
#     else:
#         ddof = _state["ddof"]
# 
#     # Handle centering
#     if "center" not in _state:
#         if isinstance(center, bool) and center:
#             _state["center"] = numpy.mean(data, axis=0)
#         elif not isinstance(center, bool):
#             _state["center"] = numpy.array(center)
#         else:
#             _state["center"] = None
#     if _state["center"] is not None:
#         data = data - _state["center"]
# 
#     # Handle scaling
#     if "scale" not in _state:
#         if isinstance(scale, bool) and scale:
#             _state["scale"] = numpy.sqrt(
#                 numpy.sum(data ** 2, axis=0) / (data.shape[0] - ddof)
#             )
#         elif not isinstance(scale, bool):
#             _state["scale"] = numpy.array(scale)
#         else:
#             _state["scale"] = None
#     if _state["scale"] is not None:
#         data = data / _state["scale"]
# 
#     return data
# 
# @stateful_transform
# def center(data, _state=None):
#     return scale(data, scale=False, _state=_state)


import numpy
import pytest
import scipy.sparse as spsparse
from formulaic.errors import DataMismatchWarning
from formulaic.transforms import center, scale



def test_scale():
    state = {}
    assert numpy.allclose(scale(data=[1, 2, 3], _state=state), [-1, 0, 1])
    assert state == {"center": 2.0, "scale": 1.0, "ddof": 1}

# Path: formulaic/errors.py
# class DataMismatchWarning(FormulaicWarning):
#     pass
# 
# Path: formulaic/transforms/scale.py
# @stateful_transform
# def scale(data, center=True, scale=True, ddof=1, _state=None):
# 
#     data = numpy.array(data)
# 
#     if "ddof" not in _state:
#         _state["ddof"] = ddof
#     else:
#         ddof = _state["ddof"]
# 
#     # Handle centering
#     if "center" not in _state:
#         if isinstance(center, bool) and center:
#             _state["center"] = numpy.mean(data, axis=0)
#         elif not isinstance(center, bool):
#             _state["center"] = numpy.array(center)
#         else:
#             _state["center"] = None
#     if _state["center"] is not None:
#         data = data - _state["center"]
# 
#     # Handle scaling
#     if "scale" not in _state:
#         if isinstance(scale, bool) and scale:
#             _state["scale"] = numpy.sqrt(
#                 numpy.sum(data ** 2, axis=0) / (data.shape[0] - ddof)
#             )
#         elif not isinstance(scale, bool):
#             _state["scale"] = numpy.array(scale)
#         else:
#             _state["scale"] = None
#     if _state["scale"] is not None:
#         data = data / _state["scale"]
# 
#     return data
# 
# @stateful_transform
# def center(data, _state=None):
#     return scale(data, scale=False, _state=_state)


# Path: tests/transforms/test_scale.py
import numpy
import pytest
import scipy.sparse as spsparse
from formulaic.errors import DataMismatchWarning
from formulaic.transforms import center, scale




def test_scale():
    state = {}
    assert numpy.allclose(scale(data=[1, 2, 3], _state=state), [-1, 0, 1])
    assert state == {"center": 2.0, "scale": 1.0, "ddof": 1}

    assert numpy.allclose(scale(data=[5, 6, 7], _state=state), [3, 4, 5])