Repository: pandas-dev/pandas
Pull request: adds non regression test for GH27358
- [X] closes #27358
- [X] tests added / passed
- [ ] passes `black pandas`
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Problem statement:
crash when calling DataFrame.from_records
#### Code Sample, a copy-pastable example if possible

```python
# each line of `data` is a list containing a single dict
data = pd.Series([[{"a": 1, "b": 2}], [{"a": 3, "b": 4}]])
crash = pd.DataFrame.from_records(data)
```


#### Problem description

The above code results in a crash of the jupyter kernel

#### Expected Output

`crash` should be a DataFrame 

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-54-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: fr_FR.UTF-8

pandas: 0.24.2
pytest: 5.0.0
pip: 19.0.3
setuptools: 41.0.0
Cython: None
numpy: 1.16.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.6.1
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.1.0
openpyxl: None
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.3.5
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

</details>

Hints from issue discussion:
Are you getting a traceback?
this is fine on master
no traceback, jupyter crashes (on various machines). If it's fine on master, I can close this (maybe you want me to add a test). In a IPython REPL with the same version of pandas, IPython segfaults

Commit message: adds non regression test for GH27358

Patch to review:
diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py
index a3817d3c226f5..547fbfa4fa45d 100644
--- a/pandas/tests/frame/test_constructors.py
+++ b/pandas/tests/frame/test_constructors.py
@@ -2427,6 +2427,13 @@ class List(list):
         result = DataFrame(List([List([1, 2, 3]), List([4, 5, 6])]))
         tm.assert_frame_equal(result, expected)
 
+    def test_from_records_series_list_dict(self):
+        # GH27358
+        expected = pd.DataFrame([[{"a": 1, "b": 2}, {"a": 3, "b": 4}]]).T
+        data = Series([[{"a": 1, "b": 2}], [{"a": 3, "b": 4}]])
+        result = pd.DataFrame.from_records(data)
+        tm.assert_frame_equal(result, expected)
+
 
 class TestDataFrameConstructorWithDatetimeTZ:
     def test_from_dict(self):


Code review comments:
diff_hunk: @@ -2427,6 +2427,13 @@ class List(list):
         result = DataFrame(List([List([1, 2, 3]), List([4, 5, 6])]))
         tm.assert_frame_equal(result, expected)
 
+    def test_from_records_series_list_dict(self):
+        # GH27358
+        expected = pd.DataFrame([[{"a": 1, "b": 2}, {"a": 3, "b": 4}]]).T
+        data = Series([[{"a": 1, "b": 2}], [{"a": 3, "b": 4}]])
+        result = pd.DataFrame.from_records(data)
path: pandas/tests/frame/test_constructors.py
text: @user1:
use DataFrame not pd.