Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for dtype in [
dtypes.Int,
dtypes.Int8,
dtypes.Int16,
dtypes.Int32,
dtypes.Int64]:
schema = DataFrameSchema({"col": Column(dtype, nullable=False)})
validated_df = schema.validate(
pd.DataFrame(
{"col": [-712, -4, -321, 0, 1, 777, 5, 123, 9000]},
dtype=dtype.value))
assert isinstance(validated_df, pd.DataFrame)
for dtype in [
dtypes.UInt8,
dtypes.UInt16,
dtypes.UInt32,
dtypes.UInt64]:
schema = DataFrameSchema({"col": Column(dtype, nullable=False)})
validated_df = schema.validate(
pd.DataFrame(
{"col": [1, 777, 5, 123, 9000]}, dtype=dtype.value))
assert isinstance(validated_df, pd.DataFrame)
def test_numeric_dtypes():
for dtype in [
dtypes.Float,
dtypes.Float16,
dtypes.Float32,
dtypes.Float64]:
schema = DataFrameSchema({"col": Column(dtype, nullable=False)})
validated_df = schema.validate(
pd.DataFrame(
{"col": [-123.1, -7654.321, 1.0, 1.1, 1199.51, 5.1, 4.6]},
dtype=dtype.value))
assert isinstance(validated_df, pd.DataFrame)
for dtype in [
dtypes.Int,
dtypes.Int8,
dtypes.Int16,
dtypes.Int32,
dtypes.Int64]:
def test_dtypes():
for dtype in [
dtypes.Float,
dtypes.Float16,
dtypes.Float32,
dtypes.Float64]:
schema = DataFrameSchema({"col": Column(dtype, nullable=False)})
validated_df = schema.validate(
pd.DataFrame(
{"col": [-123.1, -7654.321, 1.0, 1.1, 1199.51, 5.1, 4.6]},
dtype=dtype.value))
assert isinstance(validated_df, pd.DataFrame)
for dtype in [
dtypes.Int,
dtypes.Int8,
dtypes.Int16,
dtypes.Int32,
dtypes.Int64]:
schema = DataFrameSchema({"col": Column(dtype, nullable=False)})
validated_df = schema.validate(
pd.DataFrame(
def test_dtypes():
for dtype in [
dtypes.Float,
dtypes.Float16,
dtypes.Float32,
dtypes.Float64]:
schema = DataFrameSchema({"col": Column(dtype, nullable=False)})
validated_df = schema.validate(
pd.DataFrame(
{"col": [-123.1, -7654.321, 1.0, 1.1, 1199.51, 5.1, 4.6]},
dtype=dtype.value))
assert isinstance(validated_df, pd.DataFrame)
for dtype in [
dtypes.Int,
dtypes.Int8,
dtypes.Int16,
dtypes.Int32,
dtypes.Int64]:
def coerce_dtype(self, series: pd.Series) -> pd.Series:
"""Coerce the type of a pd.Series by the type specified in the Column
object's self._pandas_dtype
:param pd.Series series: One-dimensional ndarray with axis labels
(including time series).
:returns: ``Series`` with coerced data type
"""
_dtype = str if self._pandas_dtype is dtypes.PandasDtype.String \
else self._pandas_dtype.value
if _dtype is str:
# only coerce non-null elements to string
_series = series.copy()
_series[series.notna()] = _series[series.notna()].astype(str)
return _series
return series.astype(_dtype)