Description
Code Sample, a copy-pastable example if possible
#!/usr/bin/env python
import numpy as np
import pandas as pd
df1 = pd.DataFrame(columns=['A', 'B', 'C'])
df1[pd.Series()].shape == df1.shape # False
df2 = pd.DataFrame(index=['A', 'B', 'C'])
df2[pd.Series()].shape == df2.shape # True
df3 = pd.DataFrame(index=['A', 'B', 'C'], columns=['1', '2', '3'])
df3[pd.Series()].shape == df3.shape # False
Problem description
This issue was found when I was working on the testing of DataFrame.drop_duplicates
method (PR #22394). As the work revolved around an empty DataFrame, the results of DataFrame.duplicated
method came out to be an empty series. The problem is that when we select no data from the DataFrame (such as using an empty series), the index info remains but the column infos are basically gone, which means that the shape is altered.
Expected Output
The expected output would be the result which is exactly the same as the input before, as there are no data to begin with, but just the schema.
df1[pd.Series()].shape == df1.shape : True
df3[pd.Series()].shape == df3.shape : True
Output of pd.show_versions()
INSTALLED VERSIONS
commit: 6eb53f6
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-93-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.0.dev0+478.g6eb53f6.dirty
pytest: 3.7.1
pip: 18.0
setuptools: 28.8.0
Cython: 0.28.5
numpy: 1.15.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: 1.7.6
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None