MCPcopy Create free account
hub / github.com/apache/arrow / test_decimal_to_decimal

Function test_decimal_to_decimal

python/pyarrow/tests/test_array.py:1983–2008  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1981
1982
1983def test_decimal_to_decimal():
1984 arr = pa.array(
1985 [decimal.Decimal("1234.12"), None],
1986 type=pa.decimal128(19, 10)
1987 )
1988 result = arr.cast(pa.decimal128(15, 6))
1989 expected = pa.array(
1990 [decimal.Decimal("1234.12"), None],
1991 type=pa.decimal128(15, 6)
1992 )
1993 assert result.equals(expected)
1994
1995 msg_regexp = 'Rescaling Decimal value would cause data loss'
1996 with pytest.raises(pa.ArrowInvalid, match=msg_regexp):
1997 result = arr.cast(pa.decimal128(9, 1))
1998
1999 result = arr.cast(pa.decimal128(9, 1), safe=False)
2000 expected = pa.array(
2001 [decimal.Decimal("1234.1"), None],
2002 type=pa.decimal128(9, 1)
2003 )
2004 assert result.equals(expected)
2005
2006 with pytest.raises(pa.ArrowInvalid,
2007 match='Decimal value does not fit in precision'):
2008 result = arr.cast(pa.decimal128(5, 2))
2009
2010
2011@pytest.mark.numpy

Callers

nothing calls this directly

Calls 4

equalsMethod · 0.80
arrayMethod · 0.45
DecimalMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected