code: def test_from_tensor():
      tensor = mt.random.rand(10, 10, chunk_size=5)
      df = dataframe_from_tensor(tensor)
      assert isinstance(
          df.index_value._index_value, IndexValue.RangeIndex
      )
      assert df.dtypes[0] == tensor.dtype
  
      df = tile(df)
      assert len(df.chunks) == 4
      assert isinstance(
          df.chunks[0].index_value._index_value, IndexValue.RangeIndex
      )
      assert isinstance(df.chunks[0].index_value, IndexValue)
  
      # test converted from 1-d tensor
      tensor2 = mt.array([1, 2, 3])
      # in fact, tensor3 is (3,1)
      tensor3 = mt.array([tensor2]).T
  
      df2 = dataframe_from_tensor(tensor2)
      df3 = dataframe_from_tensor(tensor3)
      df2 = tile(df2)
      df3 = tile(df3)
      np.testing.assert_equal(df2.chunks[0].index, (0, 0))
      np.testing.assert_equal(df3.chunks[0].index, (0, 0))
  
      # test converted from scalar
      scalar = mt.array(1)
      np.testing.assert_equal(scalar.ndim, 0)
      with pytest.raises(TypeError):
          dataframe_from_tensor(scalar)
  
      # from tensor with given index
      df = dataframe_from_tensor(tensor, index=np.arange(0, 20, 2))
      df = tile(df)
      pd.testing.assert_index_equal(
          df.chunks[0].op.index, pd.Index(np.arange(0, 10, 2))
      )
      pd.testing.assert_index_equal(
          df.chunks[1].op.index, pd.Index(np.arange(0, 10, 2))
      )
      pd.testing.assert_index_equal(
          df.chunks[2].op.index, pd.Index(np.arange(10, 20, 2))
      )
      pd.testing.assert_index_equal(
          df.chunks[3].op.index, pd.Index(np.arange(10, 20, 2))
      )
  
      # from tensor with index that is a tensor as well
      df = dataframe_from_tensor(tensor, index=mt.arange(0, 20, 2))
      df = tile(df)
      assert len(df.chunks[0].inputs) == 2
      assert df.chunks[0].index_value.has_value() is False
  
      # from tensor with given columns
      df = dataframe_from_tensor(tensor, columns=list("abcdefghij"))
      df = tile(df)
      pd.testing.assert_index_equal(
          df.dtypes.index, pd.Index(list("abcdefghij"))
      )
      pd.testing.assert_index_equal(
          df.chunks[0].columns_value.to_pandas(),
          pd.Index(["a", "b", "c", "d", "e"]),
      )
      pd.testing.assert_index_equal(
          df.chunks[0].dtypes.index, pd.Index(["a", "b", "c", "d", "e"])
      )
      pd.testing.assert_index_equal(
          df.chunks[1].columns_value.to_pandas(),
          pd.Index(["f", "g", "h", "i", "j"]),
      )
      pd.testing.assert_index_equal(
          df.chunks[1].dtypes.index, pd.Index(["f", "g", "h", "i", "j"])
      )
      pd.testing.assert_index_equal(
          df.chunks[2].columns_value.to_pandas(),
          pd.Index(["a", "b", "c", "d", "e"]),
      )
      pd.testing.assert_index_equal(
          df.chunks[2].dtypes.index, pd.Index(["a", "b", "c", "d", "e"])
      )
      pd.testing.assert_index_equal(
          df.chunks[3].columns_value.to_pandas(),
          pd.Index(["f", "g", "h", "i", "j"]),
      )
      pd.testing.assert_index_equal(
          df.chunks[3].dtypes.index, pd.Index(["f", "g", "h", "i", "j"])
      )
  
      # test series from tensor
      tensor = mt.random.rand(10, chunk_size=4)
      series = series_from_tensor(tensor, name="a")
  
      assert series.dtype == tensor.dtype
      assert series.name == "a"
      pd.testing.assert_index_equal(
          series.index_value.to_pandas(), pd.RangeIndex(10)
      )
  
      series = tile(series)
      assert len(series.chunks) == 3
      pd.testing.assert_index_equal(
          series.chunks[0].index_value.to_pandas(), pd.RangeIndex(0, 4)
      )
      assert series.chunks[0].name == "a"
      pd.testing.assert_index_equal(
          series.chunks[1].index_value.to_pandas(), pd.RangeIndex(4, 8)
      )
      assert series.chunks[1].name == "a"
      pd.testing.assert_index_equal(
          series.chunks[2].index_value.to_pandas(), pd.RangeIndex(8, 10)
      )
      assert series.chunks[2].name == "a"
  
      d = OrderedDict(
          [
              (0, mt.tensor(np.random.rand(4))),
              (1, mt.tensor(np.random.rand(4))),
          ]
      )
      df = dataframe_from_1d_tileables(d)
      pd.testing.assert_index_equal(
          df.columns_value.to_pandas(), pd.RangeIndex(2)
      )
  
      df = tile(df)
  
      pd.testing.assert_index_equal(
          df.chunks[0].index_value.to_pandas(), pd.RangeIndex(4)
      )
  
      series = series_from_tensor(mt.random.rand(4))
      pd.testing.assert_index_equal(
          series.index_value.to_pandas(), pd.RangeIndex(4)
      )
  
      series = series_from_tensor(mt.random.rand(4), index=[1, 2, 3])
      pd.testing.assert_index_equal(
          series.op.index, pd.Index([1, 2, 3])
      )
  
      series = series_from_tensor(
          mt.random.rand(4), index=pd.Index([1, 2, 3], name="my_index")
      )
      pd.testing.assert_index_equal(
          series.op.index, pd.Index([1, 2, 3], name="my_index")
      )
      assert series.index_value.name == "my_index"
  
      with pytest.raises(TypeError):
          series_from_tensor(mt.ones((10, 10)))
  
      # index has wrong shape
      with pytest.raises(ValueError):
          dataframe_from_tensor(
              mt.random.rand(4, 3), index=mt.random.rand(5)
          )
  
      # columns have wrong shape
      with pytest.raises(ValueError):
          dataframe_from_tensor(
              mt.random.rand(4, 3), columns=["a", "b"]
          )
  
      # index should be 1-d
      with pytest.raises(ValueError):
          dataframe_from_tensor(
              mt.tensor(np.random.rand(3, 2)),
              index=mt.tensor(np.random.rand(3, 2)),
          )
  
      # 1-d tensors should have same shape
      with pytest.raises(ValueError):
          dataframe_from_1d_tileables(
              OrderedDict(
                  [
                      (0, mt.tensor(np.random.rand(3))),
                      (1, mt.tensor(np.random.rand(2))),
                  ]
              )
          )
  
      # index has wrong shape
      with pytest.raises(ValueError):
          dataframe_from_1d_tileables(
              {0: mt.tensor(np.random.rand(3))},
              index=mt.tensor(np.random.rand(2)),
          )
  
      # columns have wrong shape
      with pytest.raises(ValueError):
          dataframe_from_1d_tileables(
              {0: mt.tensor(np.random.rand(3))}, columns=["a", "b"]
          )
  
      # index should be 1-d
      with pytest.raises(ValueError):
          series_from_tensor(
              mt.random.rand(4), index=mt.random.rand(4, 3)
          )
  
imports: import os
  import tempfile
  import shutil
  import string
  from collections import OrderedDict
  import numpy
  import pandas
  import pytest
  from ....None import tensor
  from ....config import option_context
  from ....core import tile
  from ....tests.core import require_ray
  from ....utils import lazy_import
  from ...core import IndexValue, DatetimeIndex, Int64Index, Float64Index, MultiIndex
  from ..core import merge_small_files
  from ..dataframe import from_pandas
  from ..date_range import date_range
  from ..from_records import from_records
  from ..from_tensor import dataframe_from_tensor, series_from_tensor, dataframe_from_1d_tileables
  from ..index import from_pandas, from_tileable
  from ..read_csv import read_csv, DataFrameReadCSV
  from ..read_sql import read_sql_table, read_sql_query, DataFrameReadSQL
  from ..read_raydataset import read_ray_dataset, DataFrameReadRayDataset, read_ray_mldataset, DataFrameReadMLDataset
  from ...utils import ray_deprecate_ml_dataset
  from ..series import from_pandas
label_desc: Use image node_id 6 for calling a global function with example usage: test_from_tensor() without return types