From 690918f8d3fb08b8e2c9264991b9bd17e90fe56f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 2 Aug 2025 09:38:37 +0200 Subject: [PATCH] test: add test for historic_tick_size with small numbers part of #12054 --- tests/data/test_historic_precision.py | 91 +++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/data/test_historic_precision.py b/tests/data/test_historic_precision.py index b1af6d191..38e5a6035 100644 --- a/tests/data/test_historic_precision.py +++ b/tests/data/test_historic_precision.py @@ -90,3 +90,94 @@ def test_get_tick_size_over_time_real_data(testdatadir): assert all(result <= 0.0001) assert all(result >= 0.00000001) + + +def test_get_tick_size_over_time_small_numbers(): + """ + Test the get_tick_size_over_time function with predefined data + """ + # Create test dataframe with different levels of precision + data = { + "date": [ + Timestamp("2020-01-01 00:00:00", tz=UTC), + Timestamp("2020-01-02 00:00:00", tz=UTC), + Timestamp("2020-01-03 00:00:00", tz=UTC), + Timestamp("2020-01-15 00:00:00", tz=UTC), + Timestamp("2020-01-16 00:00:00", tz=UTC), + Timestamp("2020-01-31 00:00:00", tz=UTC), + Timestamp("2020-02-01 00:00:00", tz=UTC), + Timestamp("2020-02-15 00:00:00", tz=UTC), + Timestamp("2020-03-15 00:00:00", tz=UTC), + ], + "open": [ + 1.23456e-07, + 1.234e-07, + 1.23e-07, + 1.2e-07, + 1.23456e-07, + 1.234e-07, + 2.3456e-07, + 2.34e-07, + 2.34e-07, + ], + "high": [ + 1.23457e-07, + 1.235e-07, + 1.24e-07, + 1.3e-07, + 1.23456e-07, + 1.235e-07, + 2.3457e-07, + 2.34e-07, + 2.34e-07, + ], + "low": [ + 1.23455e-07, + 1.233e-07, + 1.22e-07, + 1.1e-07, + 1.23456e-07, + 1.233e-07, + 2.3455e-07, + 2.34e-07, + 2.34e-07, + ], + "close": [ + 1.23456e-07, + 1.234e-07, + 1.23e-07, + 1.2e-07, + 1.23456e-07, + 1.234e-07, + 2.3456e-07, + 2.34e-07, + 2.34e-07, + ], + "volume": [100, 200, 300, 400, 500, 600, 700, 800, 900], + } + + candles = DataFrame(data) + + # Calculate significant digits + result = get_tick_size_over_time(candles) + + # Check that the result is a pandas Series + assert isinstance(result, pd.Series) + + # Check that we have three months of data (Jan, Feb and March 2020 ) + assert len(result) == 3 + + # Before + assert result.asof("2019-01-01 00:00:00+00:00") is nan + # January should have 5 significant digits (based on 1.23456789 being the most precise value) + # which should be converted to 0.00001 + + assert result.asof("2020-01-01 00:00:00+00:00") == 0.000000000001 + assert result.asof("2020-01-01 00:00:00+00:00") == 0.000000000001 + assert result.asof("2020-02-25 00:00:00+00:00") == 0.00000000001 + assert result.asof("2020-03-25 00:00:00+00:00") == 0.000000001 + assert result.asof("2020-04-01 00:00:00+00:00") == 0.000000001 + # Value far past the last date should be the last value + assert result.asof("2025-04-01 00:00:00+00:00") == 0.000000001 + + assert result.iloc[0] == 0.000000000001