Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: TypeError when shifting DataFrame created by concatenation of slices and fills with values #42719

Closed
3 tasks done
wjsi opened this issue Jul 26, 2021 · 4 comments · Fixed by #42453
Closed
3 tasks done
Labels
Bug Internals Related to non-user accessible pandas implementation Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@wjsi
Copy link
Contributor

wjsi commented Jul 26, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import numpy as np
import pandas as pd
npa = np.random.RandomState(0).randint(1000, size=(20, 8))
df = pd.DataFrame(npa, columns=[f'c{i}' for i in range(8)])
pd.concat([df.iloc[:6, 3:5], df.iloc[:6, 6:8]], axis=1).shift(periods=2, axis=1, freq=None, fill_value=0)
Traceback (most recent call last):
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-9916dba4e800>", line 1, in <module>
    pd.concat([df.iloc[:6, 3:5], df.iloc[:6, 6:8]], axis=1).shift(periods=2, axis=1, freq=None, fill_value=0)
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 5313, in shift
    return super().shift(
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/pandas/core/generic.py", line 9179, in shift
    new_data = self._mgr.shift(
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 393, in shift
    result = self.reindex_indexer(
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 669, in reindex_indexer
    new_blocks = self._slice_take_blocks_ax0(
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 714, in _slice_take_blocks_ax0
    sl_type, slobj, sllen = _preprocess_slice_or_indexer(
  File "/Users/wenjun/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 2033, in _preprocess_slice_or_indexer
    raise TypeError(type(slice_or_indexer), dtype)
TypeError: (<class 'list'>, None)

Problem description

shift should work without exception. When df._data._consolidate_inplace() is called before shift, it works well.

I've submitted an issue at #42401 once v1.3.0 is released, but no one responds till v1.3.1 is released today.

Expected Output

   c3  c4   c6   c7
0   0   0  192  835
1   0   0  754  804
2   0   0  705  486
3   0   0  537  845
4   0   0  709  847
5   0   0  755  797

Output of pd.show_versions()

INSTALLED VERSIONS

commit : daec2e7
python : 3.8.5.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8

pandas : 1.4.0.dev0+292.gdaec2e73b4
numpy : 1.19.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 52.0.0.post20210125
Cython : 0.29.24
pytest : 6.2.2
hypothesis : 6.3.0
sphinx : 3.5.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : 2.7.2
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.6.1
sqlalchemy : 1.4.7
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.51.2

@wjsi wjsi added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 26, 2021
@jreback
Copy link
Contributor

jreback commented Jul 26, 2021

if this the same issue? why are you opening a new one?

@wjsi
Copy link
Contributor Author

wjsi commented Jul 26, 2021

if this the same issue? why are you opening a new one?

Yeah. I opened a new one as the old one keeps Need Triage till now.

@jreback
Copy link
Contributor

jreback commented Jul 26, 2021

pls close one of them
there are a ton of issues and you only need 1

u submitted a PR which will be looked at when someone has time

@simonjayhawkins
Copy link
Member

This is a regression from 1.2.5

first bad commit: [edbc6ea] CLN: remove unreached boolean-mask case from _preprocess_slice_or_indexer (#40401) cc @jbrockmendel

@simonjayhawkins simonjayhawkins added Internals Related to non-user accessible pandas implementation Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 26, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3.2 milestone Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Internals Related to non-user accessible pandas implementation Regression Functionality that used to work in a prior pandas version Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
3 participants