Skip to content

Commit

Permalink
test_constructors passes
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Feb 1, 2024
1 parent c2c0f63 commit b68efd3
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
Manager,
npt,
)

from pandas.core.series import Series
# ---------------------------------------------------------------------
# BlockManager Interface

Expand Down Expand Up @@ -364,17 +366,20 @@ def dict_to_mgr(
# arrays = Series(data, index=columns, dtype=object)
# missing = arrays.isna()
columns = ensure_index(columns)
arrays = [np.nan] * len(columns)
midxs = set(range(len(columns)))
data_keys = ensure_index(data.keys())
arrays = []
midxs = set()
for i, (column, array) in enumerate(zip(columns, data.values())):
if column in data_keys:
if is_scalar(array) and isna(array):
midxs.add(i)
arrays.append(array)
else:
arrays.append(np.nan)
midxs.add(i)
data_values = list(data.values())

for i, column in enumerate(columns):
try:
idx = data_keys.get_loc(column)
except KeyError:
continue
array = data_values[idx]
arrays[i] = array
if not (is_scalar(array) and isna(array)):
midxs.remove(i)

if index is None:
# GH10856
Expand Down Expand Up @@ -404,11 +409,12 @@ def dict_to_mgr(
nan_dtype = np.dtype("object")
val = construct_1d_arraylike_from_scalar(np.nan, len(index), nan_dtype)
for i in midxs:
if copy:
arrays[i] = val
else:
# GH#45369
arrays[i] = val.copy()
arrays[i] = val
# if copy:
# arrays[i] = val
# else:
# # GH#45369
# arrays[i] = val

# if index is None:
# # GH10856
Expand Down

0 comments on commit b68efd3

Please sign in to comment.