codecov[bot]: # [Codecov](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=h1) Report
> Merging [#314](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=desc) into [master](https://codecov.io/gh/OpenMined/PySyft/commit/543a66153c17d6e2885d6b7d571749fe02629ba5?src=pr&el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/OpenMined/PySyft/pull/314/graphs/tree.svg?token=W0kQS1vaXB&width=650&height=150&src=pr)](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #314      +/-   ##
==========================================
+ Coverage   82.26%   82.31%   +0.04%     
==========================================
  Files          24       24              
  Lines        3243     3252       +9     
==========================================
+ Hits         2668     2677       +9     
  Misses        575      575
```


| [Impacted Files](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tests/test\_tensor.py](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree#diff-dGVzdHMvdGVzdF90ZW5zb3IucHk=) | `94.21% <100%> (+0.04%)` | :arrow_up: |
| [syft/tensor.py](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=tree#diff-c3lmdC90ZW5zb3IucHk=) | `77.82% <100%> (+0.02%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=footer). Last update [543a661...65e98a9](https://codecov.io/gh/OpenMined/PySyft/pull/314?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/syft/tensor.py b/syft/tensor.py
index 081679d946..d374bb5ae0 100644
--- a/syft/tensor.py
+++ b/syft/tensor.py
@@ -449,7 +449,7 @@ class TensorBase(object):
             return NotImplemented
         else:
             out = self.data[position]
-            if (len(self.shape()) == 1):
+            if (len(self.shape()) == 1) and (type(position) != slice):
                 return out
             else:
                 return TensorBase(self.data[position], self.encrypted)

1dim TensorBase slice returns ndarray instead of TensorBase
Currently a slice of TensorBase returns an ndarray if `dim() == 1`. This is not the behavior expected in PyTorch

Example pytorch session:
```python
t1 = Tensor([1,2,3,4])
t1[1:]
 2
 3
 4
[torch.FloatTensor of size 3]
```

Same with TensorBase
```python
t2 = TensorBase([1,2,3,4])
t2[1:]
array([2, 3, 4])
```

see https://github.com/OpenMined/PySyft/commit/7fb592dcd4ede5b0d0cc6bdc50b98a0445ad77c0#diff-796d7f13fb1460eef9cffdccebd38faeR148

Is this a bug or expected ? 

diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index 5c46a87951..7ec07030c8 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -957,6 +957,17 @@ class IndexTests(unittest.TestCase):
         with pytest.raises(ValueError):
             t.index(3.5)
 
+    def test_index_slice_notation(self):
+        t1 = TensorBase(np.array([1, 2, 3, 4]))
+        expected1 = TensorBase(np.array([2, 3, 4]))
+        expected2 = type(t1[1:])
+        expected3 = 1
+
+        # Do not use "t.index" form in following test
+        self.assertEqual(expected1, t1[1:])
+        self.assertEqual(expected2, TensorBase)
+        self.assertEqual(expected3, t1[0])
+
     def test_index_add_(self):
         t1 = TensorBase(np.array([[0, 0, 0], [1, 1, 1], [1, 1, 1]]))
         t2 = TensorBase(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-flake8 line_profiler clint coverage
3.6
requirements.txt dev-requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
anyio==3.6.2
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
args==0.1.0
async-generator==1.10
attrs==22.2.0
Babel==2.11.0
backcall==0.2.0
bleach==4.1.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
clint==0.5.1
comm==0.1.4
contextvars==2.4
coverage==6.2
dataclasses==0.8
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
flake8==5.0.4
idna==3.10
immutables==0.19
importlib-metadata==4.2.0
iniconfig==1.1.1
ipykernel==5.5.6
ipython==7.16.3
ipython-genutils==0.2.0
ipywidgets==7.8.5
jedi==0.17.2
Jinja2==3.0.3
joblib==1.1.1
json5==0.9.16
jsonschema==3.2.0
jupyter==1.1.1
jupyter-client==7.1.2
jupyter-console==6.4.3
jupyter-core==4.9.2
jupyter-server==1.13.1
jupyterlab==3.2.9
jupyterlab-pygments==0.1.2
jupyterlab-server==2.10.3
jupyterlab_widgets==1.1.11
line-profiler==4.1.3
MarkupSafe==2.0.1
mccabe==0.7.0
mistune==0.8.4
nbclassic==0.3.5
nbclient==0.5.9
nbconvert==6.0.7
nbformat==5.1.3
nest-asyncio==1.6.0
notebook==6.4.10
numpy==1.19.5
packaging==21.3
pandocfilters==1.5.1
parso==0.7.1
pexpect==4.9.0
phe==1.5.0
pickleshare==0.7.5
pluggy==1.0.0
prometheus-client==0.17.1
prompt-toolkit==3.0.36
ptyprocess==0.7.0
py==1.11.0
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.14.0
pyparsing==3.1.4
pyRserve==1.0.4
pyrsistent==0.18.0
pytest==7.0.1
pytest-flake8==1.1.1
python-dateutil==2.9.0.post0
pytz==2025.2
pyzmq==25.1.2
requests==2.27.1
scikit-learn==0.24.2
scipy==1.5.4
Send2Trash==1.8.3
six==1.17.0
sklearn==0.0
sniffio==1.2.0
-e git+https://github.com/OpenMined/PySyft.git@543a66153c17d6e2885d6b7d571749fe02629ba5#egg=syft
terminado==0.12.1
testpath==0.6.0
threadpoolctl==3.1.0
tomli==1.2.3
tornado==6.1
traitlets==4.3.3
typing_extensions==4.1.1
urllib3==1.26.20
wcwidth==0.2.13
webencodings==0.5.1
websocket-client==1.3.1
widgetsnbextension==3.6.10
zipp==3.6.0

name: PySyft
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - anyio==3.6.2
      - argon2-cffi==21.3.0
      - argon2-cffi-bindings==21.2.0
      - args==0.1.0
      - async-generator==1.10
      - attrs==22.2.0
      - babel==2.11.0
      - backcall==0.2.0
      - bleach==4.1.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - clint==0.5.1
      - comm==0.1.4
      - contextvars==2.4
      - coverage==6.2
      - dataclasses==0.8
      - decorator==5.1.1
      - defusedxml==0.7.1
      - entrypoints==0.4
      - flake8==5.0.4
      - idna==3.10
      - immutables==0.19
      - importlib-metadata==4.2.0
      - iniconfig==1.1.1
      - ipykernel==5.5.6
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - ipywidgets==7.8.5
      - jedi==0.17.2
      - jinja2==3.0.3
      - joblib==1.1.1
      - json5==0.9.16
      - jsonschema==3.2.0
      - jupyter==1.1.1
      - jupyter-client==7.1.2
      - jupyter-console==6.4.3
      - jupyter-core==4.9.2
      - jupyter-server==1.13.1
      - jupyterlab==3.2.9
      - jupyterlab-pygments==0.1.2
      - jupyterlab-server==2.10.3
      - jupyterlab-widgets==1.1.11
      - line-profiler==4.1.3
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mistune==0.8.4
      - nbclassic==0.3.5
      - nbclient==0.5.9
      - nbconvert==6.0.7
      - nbformat==5.1.3
      - nest-asyncio==1.6.0
      - notebook==6.4.10
      - numpy==1.19.5
      - packaging==21.3
      - pandocfilters==1.5.1
      - parso==0.7.1
      - pexpect==4.9.0
      - phe==1.5.0
      - pickleshare==0.7.5
      - pluggy==1.0.0
      - prometheus-client==0.17.1
      - prompt-toolkit==3.0.36
      - ptyprocess==0.7.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pycparser==2.21
      - pyflakes==2.5.0
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pyrserve==1.0.4
      - pyrsistent==0.18.0
      - pytest==7.0.1
      - pytest-flake8==1.1.1
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyzmq==25.1.2
      - requests==2.27.1
      - scikit-learn==0.24.2
      - scipy==1.5.4
      - send2trash==1.8.3
      - six==1.17.0
      - sklearn==0.0
      - sniffio==1.2.0
      - terminado==0.12.1
      - testpath==0.6.0
      - threadpoolctl==3.1.0
      - tomli==1.2.3
      - tornado==6.1
      - traitlets==4.3.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - wcwidth==0.2.13
      - webencodings==0.5.1
      - websocket-client==1.3.1
      - widgetsnbextension==3.6.10
      - zipp==3.6.0
prefix: /opt/conda/envs/PySyft

tests/test_tensor.py::IndexTests::test_index_slice_notation
tests/test_tensor.py::DimTests::test_as_view tests/test_tensor.py::DimTests::test_dim_one tests/test_tensor.py::DimTests::test_resize tests/test_tensor.py::DimTests::test_resize_as tests/test_tensor.py::DimTests::test_view tests/test_tensor.py::DiagTests::test_one_dim_tensor_below_diag tests/test_tensor.py::DiagTests::test_one_dim_tensor_main_diag tests/test_tensor.py::DiagTests::test_one_dim_tensor_upper_diag tests/test_tensor.py::DiagTests::test_two_dim_tensor_below_diag tests/test_tensor.py::DiagTests::test_two_dim_tensor_main_diag tests/test_tensor.py::DiagTests::test_two_dim_tensor_upper_diag tests/test_tensor.py::AddTests::test_inplace tests/test_tensor.py::AddTests::test_scalar tests/test_tensor.py::AddTests::test_simple tests/test_tensor.py::CeilTests::test_ceil tests/test_tensor.py::CeilTests::test_ceil_ tests/test_tensor.py::ZeroTests::test_zero tests/test_tensor.py::FloorTests::test_floor_ tests/test_tensor.py::SubTests::test_inplace tests/test_tensor.py::SubTests::test_scalar tests/test_tensor.py::SubTests::test_simple tests/test_tensor.py::MaxTests::test_axis tests/test_tensor.py::MaxTests::test_no_dim tests/test_tensor.py::MultTests::test_inplace tests/test_tensor.py::MultTests::test_scalar tests/test_tensor.py::MultTests::test_simple tests/test_tensor.py::DivTests::test_inplace tests/test_tensor.py::DivTests::test_scalar tests/test_tensor.py::DivTests::test_simple tests/test_tensor.py::AbsTests::test_abs tests/test_tensor.py::AbsTests::test_abs_ tests/test_tensor.py::ShapeTests::test_shape tests/test_tensor.py::SqrtTests::test_sqrt tests/test_tensor.py::SqrtTests::test_sqrt_ tests/test_tensor.py::SumTests::test_dim_is_not_none_int tests/test_tensor.py::SumTests::test_dim_none_int tests/test_tensor.py::EqualTests::test_equal tests/test_tensor.py::EqualTests::test_equal_operation tests/test_tensor.py::EqualTests::test_inequality_operation tests/test_tensor.py::EqualTests::test_not_equal tests/test_tensor.py::sigmoidTests::test_sigmoid tests/test_tensor.py::addmm::test_addmm_1d tests/test_tensor.py::addmm::test_addmm_2d tests/test_tensor.py::addmm::test_addmm__1d tests/test_tensor.py::addmm::test_addmm__2d tests/test_tensor.py::addcmulTests::test_addcmul_1d tests/test_tensor.py::addcmulTests::test_addcmul_2d tests/test_tensor.py::addcmulTests::test_addcmul__1d tests/test_tensor.py::addcmulTests::test_addcmul__2d tests/test_tensor.py::addcdivTests::test_addcdiv_1d tests/test_tensor.py::addcdivTests::test_addcdiv_2d tests/test_tensor.py::addcdivTests::test_addcdiv__1d tests/test_tensor.py::addcdivTests::test_addcdiv__2d tests/test_tensor.py::addmvTests::test_addmv tests/test_tensor.py::addmvTests::test_addmv_ tests/test_tensor.py::bmmTests::test_bmm tests/test_tensor.py::bmmTests::test_bmm_size tests/test_tensor.py::addbmmTests::test_addbmm tests/test_tensor.py::addbmmTests::test_addbmm_ tests/test_tensor.py::baddbmmTests::test_baddbmm tests/test_tensor.py::baddbmmTests::test_baddbmm_ tests/test_tensor.py::transposeTests::test_t tests/test_tensor.py::transposeTests::test_transpose tests/test_tensor.py::transposeTests::test_transpose_ tests/test_tensor.py::unsqueezeTests::test_unsqueeze tests/test_tensor.py::unsqueezeTests::test_unsqueeze_ tests/test_tensor.py::expTests::test_exp tests/test_tensor.py::expTests::test_exp_ tests/test_tensor.py::fracTests::test_frac tests/test_tensor.py::fracTests::test_frac_ tests/test_tensor.py::rsqrtTests::test_rsqrt tests/test_tensor.py::rsqrtTests::test_rsqrt_ tests/test_tensor.py::signTests::test_sign tests/test_tensor.py::signTests::test_sign_ tests/test_tensor.py::numpyTests::test_numpy tests/test_tensor.py::reciprocalTests::test_reciprocal tests/test_tensor.py::reciprocalTests::test_reciprocal_ tests/test_tensor.py::logTests::test_log tests/test_tensor.py::logTests::test_log_ tests/test_tensor.py::logTests::test_log_1p tests/test_tensor.py::logTests::test_log_1p_ tests/test_tensor.py::clampTests::test_clamp_float tests/test_tensor.py::clampTests::test_clamp_float_in_place tests/test_tensor.py::clampTests::test_clamp_int tests/test_tensor.py::clampTests::test_clamp_int_in_place tests/test_tensor.py::cloneTests::test_clone tests/test_tensor.py::chunkTests::test_chunk tests/test_tensor.py::chunkTests::test_chunk_same_size tests/test_tensor.py::gtTests::test_gt__in_place_with_number tests/test_tensor.py::gtTests::test_gt__in_place_with_tensor tests/test_tensor.py::gtTests::test_gt_with_encrypted tests/test_tensor.py::gtTests::test_gt_with_number tests/test_tensor.py::gtTests::test_gt_with_tensor tests/test_tensor.py::geTests::test_ge__in_place_with_number tests/test_tensor.py::geTests::test_ge__in_place_with_tensor tests/test_tensor.py::geTests::test_ge_with_encrypted tests/test_tensor.py::geTests::test_ge_with_number tests/test_tensor.py::geTests::test_ge_with_tensor tests/test_tensor.py::ltTests::test_lt__in_place_with_number tests/test_tensor.py::ltTests::test_lt__in_place_with_tensor tests/test_tensor.py::ltTests::test_lt_with_encrypted tests/test_tensor.py::ltTests::test_lt_with_number tests/test_tensor.py::ltTests::test_lt_with_tensor tests/test_tensor.py::leTests::test_le__in_place_with_number tests/test_tensor.py::leTests::test_le__in_place_with_tensor tests/test_tensor.py::leTests::test_le_with_encrypted tests/test_tensor.py::leTests::test_le_with_number tests/test_tensor.py::leTests::test_le_with_tensor tests/test_tensor.py::bernoulliTests::test_bernoulli tests/test_tensor.py::bernoulliTests::test_bernoulli_ tests/test_tensor.py::cauchyTests::test_cauchy_ tests/test_tensor.py::uniformTests::test_uniform tests/test_tensor.py::uniformTests::test_uniform_ tests/test_tensor.py::geometricTests::test_geometric_ tests/test_tensor.py::normalTests::test_normal tests/test_tensor.py::normalTests::test_normal_ tests/test_tensor.py::fillTests::test_fill_ tests/test_tensor.py::topkTests::test_topK tests/test_tensor.py::tolistTests::test_to_list tests/test_tensor.py::traceTests::test_trace tests/test_tensor.py::roundTests::test_round tests/test_tensor.py::roundTests::test_round_ tests/test_tensor.py::repeatTests::test_repeat tests/test_tensor.py::powTests::test_pow tests/test_tensor.py::powTests::test_pow_ tests/test_tensor.py::negTests::test_neg tests/test_tensor.py::negTests::test_neg_ tests/test_tensor.py::tanhTests::test_tanh_ tests/test_tensor.py::prodTests::test_prod tests/test_tensor.py::randomTests::test_random_ tests/test_tensor.py::nonzeroTests::test_non_zero tests/test_tensor.py::cumprodTest::test_cumprod tests/test_tensor.py::cumprodTest::test_cumprod_ tests/test_tensor.py::splitTests::test_split tests/test_tensor.py::squeezeTests::test_squeeze tests/test_tensor.py::expandAsTests::test_expand_as tests/test_tensor.py::meanTests::test_mean tests/test_tensor.py::notEqualTests::test_ne tests/test_tensor.py::notEqualTests::test_ne_ tests/test_tensor.py::IndexTests::test_index tests/test_tensor.py::IndexTests::test_index_add_ tests/test_tensor.py::IndexTests::test_index_copy_ tests/test_tensor.py::IndexTests::test_index_fill_ tests/test_tensor.py::IndexTests::test_index_select tests/test_tensor.py::IndexTests::test_indexing tests/test_tensor.py::gatherTests::test_gather_numerical_1 tests/test_tensor.py::gatherTests::test_gather_numerical_2 tests/test_tensor.py::scatterTests::test_scatter_dim_out_Of_range tests/test_tensor.py::scatterTests::test_scatter_index_out_of_range tests/test_tensor.py::scatterTests::test_scatter_index_src_dimension_mismatch tests/test_tensor.py::scatterTests::test_scatter_index_type tests/test_tensor.py::scatterTests::test_scatter_numerical_0 tests/test_tensor.py::scatterTests::test_scatter_numerical_1 tests/test_tensor.py::scatterTests::test_scatter_numerical_2 tests/test_tensor.py::scatterTests::test_scatter_numerical_3 tests/test_tensor.py::scatterTests::test_scatter_numerical_4 tests/test_tensor.py::scatterTests::test_scatter_numerical_5 tests/test_tensor.py::scatterTests::test_scatter_numerical_6 tests/test_tensor.py::remainderTests::test_remainder_ tests/test_tensor.py::remainderTests::test_remainder_broadcasting tests/test_tensor.py::testMv::test_mv tests/test_tensor.py::testMv::test_mv_tensor tests/test_tensor.py::masked_scatter_Tests::test_masked_scatter_1 tests/test_tensor.py::masked_scatter_Tests::test_masked_scatter_braodcasting_1 tests/test_tensor.py::masked_scatter_Tests::test_masked_scatter_braodcasting_2 tests/test_tensor.py::masked_fill_Tests::test_masked_fill_ tests/test_tensor.py::masked_fill_Tests::test_masked_fill_broadcasting tests/test_tensor.py::masked_select_Tests::test_masked_select tests/test_tensor.py::masked_select_Tests::test_masked_select_broadcasting_1 tests/test_tensor.py::masked_select_Tests::test_masked_select_broadcasting_2 tests/test_tensor.py::masked_select_Tests::test_tensor_base_masked_select tests/test_tensor.py::eqTests::test_eq_in_place_with_number tests/test_tensor.py::eqTests::test_eq_in_place_with_tensor tests/test_tensor.py::eqTests::test_eq_with_number tests/test_tensor.py::eqTests::test_eq_with_tensor tests/test_tensor.py::mm_test::test_mm_1d tests/test_tensor.py::mm_test::test_mm_2d tests/test_tensor.py::mm_test::test_mm_3d tests/test_tensor.py::newTensorTests::test_encrypted_error tests/test_tensor.py::newTensorTests::test_return_new_float_tensor tests/test_tensor.py::newTensorTests::test_return_new_int_tensor tests/test_tensor.py::fmodTest::test_fmod_number tests/test_tensor.py::fmodTest::test_fmod_tensor tests/test_tensor.py::fmod_Test::test_fmod_number tests/test_tensor.py::fmod_Test::test_fmod_tensor tests/test_tensor.py::lerpTests::test_lerp tests/test_tensor.py::lerpTests::test_lerp_ tests/test_tensor.py::RenormTests::testRenorm tests/test_tensor.py::RenormTests::testRenorm_
syft/tensor.py
syft/tensor.py