dataframe_test.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. # isort:skip_file
  18. import numpy as np
  19. import pandas as pd
  20. import tests.test_app
  21. from superset.dataframe import df_to_records
  22. from superset.db_engine_specs import BaseEngineSpec
  23. from superset.result_set import SupersetResultSet
  24. from .base_tests import SupersetTestCase
  25. class SupersetDataFrameTestCase(SupersetTestCase):
  26. def test_df_to_records(self):
  27. data = [("a1", "b1", "c1"), ("a2", "b2", "c2")]
  28. cursor_descr = (("a", "string"), ("b", "string"), ("c", "string"))
  29. results = SupersetResultSet(data, cursor_descr, BaseEngineSpec)
  30. df = results.to_pandas_df()
  31. self.assertEqual(
  32. df_to_records(df),
  33. [{"a": "a1", "b": "b1", "c": "c1"}, {"a": "a2", "b": "b2", "c": "c2"}],
  34. )
  35. def test_js_max_int(self):
  36. data = [(1, 1239162456494753670, "c1"), (2, 100, "c2")]
  37. cursor_descr = (("a", "int"), ("b", "int"), ("c", "string"))
  38. results = SupersetResultSet(data, cursor_descr, BaseEngineSpec)
  39. df = results.to_pandas_df()
  40. self.assertEqual(
  41. df_to_records(df),
  42. [
  43. {"a": 1, "b": "1239162456494753670", "c": "c1"},
  44. {"a": 2, "b": 100, "c": "c2"},
  45. ],
  46. )