Pycharm linter flags output of concat as "type", not DataFrame · Issue #17079 · pandas-dev/pandas (original) (raw)

Minimum display example

df1 = pd.DataFrame({'A': ['A0']}, index=[0]) df2 = pd.DataFrame({'A': ['A4']}, index=[4]) result = pd.concat([df1, df2])

print(df1.loc[4]) # Pycharm doesn't flag print(result.loc[4]) # Pycharm flags as "Unresolved attribute reference '.loc' for class 'type'" # But runs fine anyway

Problem description

Pycharm's linter believes pd.concat as returning class "type", when it normally returns a dataframe.

I suspect that this is due to core.reshape.concat._Concatenator.get_result() using core.dtypes.concat._get_frame_result_type which sometimes returns SparseDataFrame (a type) and sometimes an object (normally a Dataframe?).

Extract from pandas.core.dtypes.concat

def _get_frame_result_type(result, objs): """ return appropriate class of DataFrame-like concat if any block is SparseBlock, return SparseDataFrame otherwise, return 1st obj """ if any(b.is_sparse for b in result.blocks): from pandas.core.sparse.api import SparseDataFrame return SparseDataFrame else: return objs[0]

Expected Output

The MDE should not throw an error in Pycharm.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.2.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.13.1
scipy: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: 2.4.8
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
pandas_gbq: None
pandas_datareader: None
None

I am using Pycharm Community Edition 2017.1.5.