--- /dev/null
+.. change::
+ :tags: bug, oracle
+ :tickets: 4064
+
+ Added some additional rules to fully handle ``Decimal('Infinity')``,
+ ``Decimal('-Infinity')`` values with cx_Oracle numerics when using
+ ``asdecimal=True``.
def process(value):
if isinstance(value, (int, float)):
return processor(value)
+ elif value is not None and value.is_infinite():
+ return float(value)
else:
return value
return process
outconverter = None
if precision:
if self.asdecimal:
- if is_cx_oracle_6:
+ if default_type == cx_Oracle.NATIVE_FLOAT:
+ # receiving float and doing Decimal after the fact
+ # allows for float("inf") to be handled
+ type_ = default_type
+ outconverter = decimal.Decimal
+ elif is_cx_oracle_6:
type_ = decimal.Decimal
else:
type_ = cx_Oracle.STRING
type_ = cx_Oracle.NATIVE_FLOAT
else:
if self.asdecimal:
- if is_cx_oracle_6:
+ if default_type == cx_Oracle.NATIVE_FLOAT:
+ type_ = default_type
+ outconverter = decimal.Decimal
+ elif is_cx_oracle_6:
type_ = decimal.Decimal
else:
type_ = cx_Oracle.STRING
filter_=lambda n: n is not None and round(n, 5) or None
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
@testing.requires.precision_generic_float_type
def test_float_custom_scale(self):
self._do_test(
check_scale=True
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
def test_numeric_as_decimal(self):
self._do_test(
Numeric(precision=8, scale=4),
[decimal.Decimal("15.7563")],
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
def test_numeric_as_float(self):
self._do_test(
Numeric(precision=8, scale=4, asdecimal=False),
[15.7563],
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
@testing.requires.fetch_null_from_numeric
def test_numeric_null_as_decimal(self):
self._do_test(
[None],
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
@testing.requires.floats_to_four_decimals
def test_float_as_decimal(self):
self._do_test(
[decimal.Decimal("15.7563"), None],
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
def test_float_as_float(self):
self._do_test(
Float(precision=8),
# )
# eq_(val, expr)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
@testing.requires.precision_numerics_general
def test_precision_decimal(self):
numbers = set([
numbers,
)
- @testing.skip_if(
- "oracle", "temporary skip until cx_oracle refactor is merged")
@testing.requires.precision_numerics_enotation_large
def test_enotation_decimal(self):
"""test exceedingly small decimals.
Column("intcol", Integer),
Column("numericcol", oracle.BINARY_DOUBLE(asdecimal=False)))
t1.create()
- t1.insert().execute(
- intcol=1,
- numericcol=float("inf"),
+ t1.insert().execute([
+ dict(
+ intcol=1,
+ numericcol=float("inf")
+ ),
+ dict(
+ intcol=2,
+ numericcol=float("-inf")
+ ),
+ ])
+
+ eq_(
+ select([t1.c.numericcol]).
+ order_by(t1.c.intcol).execute().fetchall(),
+ [(float('inf'), ), (float('-inf'), )]
+ )
+
+ eq_(
+ testing.db.execute(
+ "select numericcol from t1 order by intcol").fetchall(),
+ [(float('inf'), ), (float('-inf'), )]
)
+ @testing.provide_metadata
+ def test_numeric_infinity_decimal(self):
+ m = self.metadata
+ t1 = Table('t1', m,
+ Column("intcol", Integer),
+ Column("numericcol", oracle.BINARY_DOUBLE(asdecimal=True)))
+ t1.create()
+ t1.insert().execute([
+ dict(
+ intcol=1,
+ numericcol=decimal.Decimal("Infinity")
+ ),
+ dict(
+ intcol=2,
+ numericcol=decimal.Decimal("-Infinity")
+ ),
+ ])
+
eq_(
- select([t1.c.numericcol]).scalar(),
- float("inf")
+ select([t1.c.numericcol]).
+ order_by(t1.c.intcol).execute().fetchall(),
+ [(decimal.Decimal("Infinity"), ), (decimal.Decimal("-Infinity"), )]
)
eq_(
- testing.db.scalar("select numericcol from t1"),
- float("inf"))
+ testing.db.execute(
+ "select numericcol from t1 order by intcol").fetchall(),
+ [(decimal.Decimal("Infinity"), ), (decimal.Decimal("-Infinity"), )]
+ )
@testing.provide_metadata
def test_numerics_broken_inspection(self):