Skip to content

Commit 56f8ae4

Browse files
committed
stay packed for nested[['sub_column']]
1 parent fb3dda6 commit 56f8ae4

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

src/nested_pandas/series/accessor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ def __getitem__(self, key: str | list[str]) -> NestedSeries:
508508
# on the number of fields requested and their dtypes
509509
if isinstance(key, list):
510510
new_array = self._series.array.view_fields(key)
511-
if len(key) == 1 and not isinstance(new_array.dtype.field_dtype(key[0]), NestedDtype):
512-
# If only one field is requested, return it as a pd.Series
513-
return self._series[key[0]]
511+
# if len(key) == 1 and not isinstance(new_array.dtype.field_dtype(key[0]), NestedDtype):
512+
# # If only one field is requested, return it as a pd.Series
513+
# return self._series[key[0]]
514514
return NestedSeries(new_array, index=self._series.index, name=self._series.name)
515515

516516
# If the key is a single string, return the flat series for that field

tests/nested_pandas/nestedframe/test_nestedframe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def test_get_nested_columns():
182182

183183
base = base.add_nested(nested, "nested")
184184

185+
# import pdb;pdb.set_trace()
185186
df = base[["a", "b", "nested.c"]]
186187
assert np.all(df.columns == ["a", "b", "nested"])
187188
assert df.dtypes["nested"].field_names == ["c"]

tests/nested_pandas/series/test_accessor.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -769,27 +769,6 @@ def test___getitem___series_masking():
769769
_ = nf["nested"].nest[mask[0:23]]
770770

771771

772-
def test___getitem___single_list_field():
773-
"""Test that the .nest["field"] works for a single list field."""
774-
struct_array = pa.StructArray.from_arrays(
775-
arrays=[
776-
pa.array([np.array([1, 2, 3]), np.array([4, 5, 6])]),
777-
pa.array([np.array([6, 4, 2]), np.array([1, 2, 3])]),
778-
],
779-
names=["a", "b"],
780-
)
781-
series = NestedSeries(struct_array, dtype=NestedDtype(struct_array.type), index=[5, 7])
782-
assert_series_equal(
783-
series.nest[["a"]],
784-
pd.Series(
785-
data=[1, 2, 3, 4, 5, 6],
786-
index=[5, 5, 5, 7, 7, 7],
787-
name="a",
788-
dtype=pd.ArrowDtype(pa.int64()),
789-
),
790-
)
791-
792-
793772
def test___setitem__():
794773
"""Test that the .nest["field"] = ... works for a single field."""
795774
struct_array = pa.StructArray.from_arrays(

0 commit comments

Comments
 (0)