@@ -5996,4 +5996,50 @@ def test_sleef_purecfma_symbols():
59965996 for sym in purecfma_symbols [:5 ]:
59975997 print (f" { sym } " )
59985998 if len (purecfma_symbols ) > 5 :
5999- print (f" ... and { len (purecfma_symbols ) - 5 } more" )
5999+ print (f" ... and { len (purecfma_symbols ) - 5 } more" )
6000+
6001+
6002+ def test_empty_construct ():
6003+ # Default backend (sleef): no-arg construction yields zero.
6004+ assert QuadPrecision () == QuadPrecision (0 ) == 0
6005+ assert QuadPrecision ().dtype == QuadPrecDType ()
6006+ assert str (QuadPrecision ()) == str (QuadPrecision (0 ))
6007+
6008+ # longdouble backend: no-arg construction also yields zero.
6009+ assert QuadPrecision (backend = "longdouble" ) == QuadPrecision (0 , backend = "longdouble" ) == 0
6010+ assert QuadPrecision (backend = "longdouble" ).dtype == QuadPrecDType (backend = "longdouble" )
6011+
6012+ # Round-trip through dtype.type(), this is the call path pandas uses
6013+ # in `_take_preprocess_indexer_and_fill_value` (see issue #83).
6014+ for backend in ("sleef" , "longdouble" ):
6015+ dtype = QuadPrecDType (backend = backend )
6016+ zero = dtype .type ()
6017+ assert isinstance (zero , QuadPrecision )
6018+ assert zero == 0
6019+
6020+ # Invalid backend must still raise even when no value is supplied.
6021+ with pytest .raises (ValueError ):
6022+ QuadPrecision (backend = "bogus" )
6023+
6024+ # Explicit None should NOT be silently treated as zero, it must go
6025+ # through QuadPrecision_from_object and raise.
6026+ with pytest .raises ((TypeError , ValueError )):
6027+ QuadPrecision (None )
6028+
6029+
6030+ def test_pandas_strrep ():
6031+ """Test that we can construct a pandas data frame with quad precision columns
6032+
6033+ Make sure the string representation can be generated
6034+ """
6035+ import pandas as pd
6036+
6037+ BIG_NUMBER = 123456789098765432123456789
6038+ x = np .arange (500 , dtype = np .float64 ) * BIG_NUMBER
6039+ y = np .arange (500 , dtype = QuadPrecDType ()) * BIG_NUMBER
6040+ df = pd .DataFrame ({"col1" : x , "col2" : y })
6041+ assert isinstance (str (df ), str ) # Make sure this doesn't fail
6042+ assert df ["col1" ].dtype == np .float64
6043+ assert df ["col2" ].dtype == QuadPrecDType ()
6044+ assert df ["col1" ].iloc [499 ] != QuadPrecision (499 * BIG_NUMBER )
6045+ assert df ["col2" ].iloc [499 ] == QuadPrecision (499 * BIG_NUMBER )
0 commit comments