Skip to content

Commit 8615e3c

Browse files
Merge branch 'release/0.10.10'
2 parents 468dc7c + 3e51de2 commit 8615e3c

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
**/.coverage.*
1010
**/checkpoint_restart.dat
1111
build/
12+
xdeps/refs.c

tests/test_table.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,33 @@ def test_table_row_iter_underscore():
465465

466466
rb = table2.rows.at('b')
467467
assert rb.name == 'b'
468-
assert rb._b == 2
468+
assert rb._b == 2
469+
470+
def test_table_does_not_create_cyclic_garbage():
471+
import gc
472+
473+
def create_table():
474+
data = {
475+
"name": np.array(["a", "b", "c"]),
476+
"c1": np.array([1, 2, 3]),
477+
"c2": np.array([4, 5, 6]),
478+
}
479+
table = Table(data)
480+
_ = table.rows
481+
_ = table.cols
482+
483+
# Collect any existing garbage
484+
gc.collect()
485+
486+
# Disable automatic garbage collection temporarily, reference counting
487+
# still works, and we want to check that it is sufficient.
488+
gc.disable()
489+
490+
try:
491+
for _ in range(5):
492+
create_table()
493+
494+
collected_count = gc.collect()
495+
assert collected_count == 0
496+
finally:
497+
gc.enable()

xdeps/table.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ def __init__(
231231

232232
# special init due to setattr redefinition
233233
init = {
234-
# "header": header,
235-
"cols": _ColView(self),
236-
"rows": _RowView(self),
237234
"_data": _data,
238235
"_col_names": _col_names,
239236
"_index": index,
@@ -253,6 +250,14 @@ def __init__(
253250
for kk in self._col_names:
254251
self._data[kk] = self._data[kk].copy()
255252

253+
@property
254+
def rows(self):
255+
return _RowView(self)
256+
257+
@property
258+
def cols(self):
259+
return _ColView(self)
260+
256261
@property
257262
def mask(self):
258263
raise DeprecationWarning(
@@ -972,7 +977,17 @@ def to_pandas(self, index=None, columns=None):
972977

973978
import pandas as pd
974979

975-
df = pd.DataFrame(self._data, columns=self._col_names)
980+
df_data = {}
981+
982+
for name in columns:
983+
column = self._data[name]
984+
985+
if isinstance(column, np.ndarray) and column.ndim > 1:
986+
df_data[name] = column.tolist()
987+
else:
988+
df_data[name] = column
989+
990+
df = pd.DataFrame(df_data, columns=columns)
976991
if index is not None:
977992
df.set_index(index, inplace=True)
978993
return df

0 commit comments

Comments
 (0)