Skip to content

Commit dfdd925

Browse files
authored
Merge pull request #20 from tessgi/refactor-dataframe
Renamed Frame products to SeriesCollection
2 parents 1ea9357 + 2323274 commit dfdd925

7 files changed

Lines changed: 91 additions & 74 deletions

File tree

src/lkdata/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33
from __future__ import absolute_import
44
from .version import __version__ # noqa: E402, F401
55
from .datacube import DataCube, BoolCube, BitwiseCube # noqa: F403, E402
6-
from .dataframe import DataFrame, BoolFrame, BitwiseFrame # noqa: F403, E402
6+
from .seriescollection import (
7+
DataSeriesCollection,
8+
BoolSeriesCollection,
9+
BitwiseSeriesCollection,
10+
) # noqa: F403, E402
711
from .dataseries import DataSeries, BoolSeries, BitwiseSeries # noqa: F403, E402
812
from .dataset import DataSet # noqa: E402
913
import os
1014

1115
__all__ = [
1216
"DataCube",
13-
"DataFrame",
17+
"DataSeriesCollection",
1418
"DataSeries",
1519
"DataSet",
1620
"BoolCube",
17-
"BoolFrame",
21+
"BoolSeriesCollection",
1822
"BoolSeries",
1923
"BitwiseCube",
20-
"BitwiseFrame",
24+
"BitwiseSeriesCollection",
2125
"BitwiseSeries",
2226
]
2327

src/lkdata/datacube.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import numpy as np
99
from typing import Union, List, Dict, Optional
1010

11-
from .dataframe import DataFrame, BoolFrame, BitwiseFrame
11+
from .seriescollection import (
12+
DataSeriesCollection,
13+
BoolSeriesCollection,
14+
BitwiseSeriesCollection,
15+
)
1216
from .dataseries import DataSeries, BoolSeries, BitwiseSeries
1317
from .mixins import (
1418
StatsMixin,
@@ -480,7 +484,7 @@ def to_dataframe(
480484
row: Union[int, float, list, slice],
481485
col: Union[int, float, list, slice],
482486
**kwargs,
483-
) -> DataFrame:
487+
) -> DataSeriesCollection:
484488
"""Convert lkdata.Cube to lkdata.Frame with the given row and column.
485489
486490
Parameters
@@ -528,7 +532,7 @@ class DataCube(
528532
):
529533
"""A Cube object which contains data with time and 2 spatial dimensions."""
530534

531-
_frame_class = DataFrame
535+
_frame_class = DataSeriesCollection
532536
_series_class = DataSeries
533537

534538
def __init__(
@@ -570,7 +574,7 @@ class BoolCube(
570574
):
571575
"""A Cube object which contains boolean values with time and 2 spatial dimensions."""
572576

573-
_frame_class = BoolFrame
577+
_frame_class = BoolSeriesCollection
574578
_series_class = BoolSeries
575579

576580
def __init__(
@@ -596,7 +600,7 @@ def __repr__(self):
596600
class BitwiseCube(BitwiseMixin, Cube):
597601
"""A Cube object which contains bitwise values with time and 2 spatial dimensions."""
598602

599-
_frame_class = BitwiseFrame
603+
_frame_class = BitwiseSeriesCollection
600604
_series_class = BitwiseSeries
601605

602606
def __init__(

src/lkdata/dataset.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,27 @@
1212
import pandas as pd
1313

1414
from .datacube import Cube, DataCube, BoolCube, BitwiseCube
15-
from .dataframe import Frame, DataFrame, BoolFrame, BitwiseFrame
15+
from .seriescollection import (
16+
SeriesCollection,
17+
DataSeriesCollection,
18+
BoolSeriesCollection,
19+
BitwiseSeriesCollection,
20+
)
1621
from .dataseries import Series, DataSeries, BoolSeries, BitwiseSeries
1722
from .mixins import IndexProcessorMixin
1823

19-
LkDataTypes = Union[DataCube, DataFrame, DataSeries]
20-
LkBoolTypes = Union[BoolCube, BoolFrame, BoolSeries]
21-
LkBitwiseTypes = Union[BitwiseCube, BitwiseFrame, BitwiseSeries]
24+
LkDataTypes = Union[DataCube, DataSeriesCollection, DataSeries]
25+
LkBoolTypes = Union[BoolCube, BoolSeriesCollection, BoolSeries]
26+
LkBitwiseTypes = Union[BitwiseCube, BitwiseSeriesCollection, BitwiseSeries]
2227
LkTypes = Union[LkDataTypes, LkBoolTypes, LkBitwiseTypes]
2328

2429
CLS_STRINGS = {
2530
DataCube: "DataCube",
2631
BoolCube: "BoolCube",
2732
BitwiseCube: "BitwiseCube",
28-
DataFrame: "DataFrame",
29-
BoolFrame: "BoolFrame",
30-
BitwiseFrame: "BitwiseFrame",
33+
DataSeriesCollection: "DataFrame",
34+
BoolSeriesCollection: "BoolFrame",
35+
BitwiseSeriesCollection: "BitwiseFrame",
3136
DataSeries: "DataSeries",
3237
BoolSeries: "BoolSeries",
3338
BitwiseSeries: "BitwiseSeries",
@@ -182,13 +187,13 @@ def process_input(self, input_data) -> LkTypes:
182187
"""
183188

184189
@process_input.register(DataCube)
185-
@process_input.register(DataFrame)
190+
@process_input.register(DataSeriesCollection)
186191
@process_input.register(DataSeries)
187192
@process_input.register(BoolCube)
188-
@process_input.register(BoolFrame)
193+
@process_input.register(BoolSeriesCollection)
189194
@process_input.register(BoolSeries)
190195
@process_input.register(BitwiseCube)
191-
@process_input.register(BitwiseFrame)
196+
@process_input.register(BitwiseSeriesCollection)
192197
@process_input.register(BitwiseSeries)
193198
def _(self, input_data):
194199
self._check_attrs(input_data)
@@ -230,7 +235,7 @@ class ProductBundle(dict, DataProcessorMixin):
230235

231236
_type: str = None
232237
_cube: Cube = Cube
233-
_frame: Frame = Frame
238+
_frame: SeriesCollection = SeriesCollection
234239
_series: Series = Series
235240

236241
_index: pd.MultiIndex = None
@@ -318,13 +323,13 @@ def _(self, input_data: dict):
318323
return input_data
319324

320325
@_unpack_input.register(DataCube)
321-
@_unpack_input.register(DataFrame)
326+
@_unpack_input.register(DataSeriesCollection)
322327
@_unpack_input.register(DataSeries)
323328
@_unpack_input.register(BoolCube)
324-
@_unpack_input.register(BoolFrame)
329+
@_unpack_input.register(BoolSeriesCollection)
325330
@_unpack_input.register(BoolSeries)
326331
@_unpack_input.register(BitwiseCube)
327-
@_unpack_input.register(BitwiseFrame)
332+
@_unpack_input.register(BitwiseSeriesCollection)
328333
@_unpack_input.register(BitwiseSeries)
329334
def _(self, input_data):
330335
default_key = CLS_STRINGS.get(type(input_data))
@@ -388,7 +393,7 @@ class DataProducts(ProductBundle):
388393

389394
_type = "data"
390395
_cube = DataCube
391-
_frame = DataFrame
396+
_frame = DataSeriesCollection
392397
_series = DataSeries
393398

394399
def __init__(
@@ -406,7 +411,7 @@ def __init__(
406411
class BoolProducts(ProductBundle):
407412
_type = "bool"
408413
_cube = BoolCube
409-
_frame = BoolFrame
414+
_frame = BoolSeriesCollection
410415
_series = BoolSeries
411416

412417
def __init__(
@@ -424,7 +429,7 @@ def __init__(
424429
class BitwiseProducts(ProductBundle):
425430
_type = "bitwise"
426431
_cube = BitwiseCube
427-
_frame = BitwiseFrame
432+
_frame = BitwiseSeriesCollection
428433
_series = BitwiseSeries
429434

430435
def __init__(
@@ -586,7 +591,7 @@ def _(self, key: tuple):
586591
{
587592
data_key: data[time_key]
588593
for data_key, data in self.data_products.items()
589-
if isinstance(data, (DataSeries, DataFrame))
594+
if isinstance(data, (DataSeries, DataSeriesCollection))
590595
}
591596
)
592597

@@ -611,7 +616,7 @@ def _(self, key: tuple):
611616
{
612617
data_key: data[time_key]
613618
for data_key, data in self.bool_products.items()
614-
if isinstance(data, (BoolSeries, BoolFrame))
619+
if isinstance(data, (BoolSeries, BoolSeriesCollection))
615620
}
616621
)
617622

@@ -631,7 +636,7 @@ def _(self, key: tuple):
631636
{
632637
data_key: data[time_key]
633638
for data_key, data in self.bitwise_products.items()
634-
if isinstance(data, (BitwiseSeries, BitwiseFrame))
639+
if isinstance(data, (BitwiseSeries, BitwiseSeriesCollection))
635640
}
636641
)
637642

@@ -769,7 +774,7 @@ def frames(self) -> dict:
769774
frames = {
770775
key: value
771776
for key, value in self.contents.items()
772-
if issubclass(type(value), Frame)
777+
if issubclass(type(value), SeriesCollection)
773778
}
774779
return frames
775780

tests/test_datacube.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from lkdata import (
77
TESTDATA,
88
DataCube,
9-
DataFrame,
9+
DataSeriesCollection,
1010
DataSeries,
1111
BoolCube,
1212
)
@@ -115,12 +115,12 @@ def test_slicing():
115115
assert df[:, :2, :2].ncol == 2
116116

117117
# Mixed slice and indices
118-
assert isinstance(df[:, [0, 1], :2], DataFrame)
118+
assert isinstance(df[:, [0, 1], :2], DataSeriesCollection)
119119
assert df[:, [0, 1], :2].ntime == ntime
120120
assert df[:, [0, 1], :2].nseries == 4
121121

122122
assert all(df[:, [0, 1], 0] == df[:, [0, 1], [0, 0]])
123-
assert isinstance(df[:, [0, 1], 0], DataFrame)
123+
assert isinstance(df[:, [0, 1], 0], DataSeriesCollection)
124124
assert df[:, [0, 1], 0].ntime == ntime
125125
assert df[:, [0, 1], 0].nseries == 2
126126

@@ -130,27 +130,27 @@ def test_slicing():
130130

131131
# Frames - timeseries for multiple pixels
132132
row, col = np.where(aperture)
133-
assert isinstance(df[:, row, col], DataFrame)
133+
assert isinstance(df[:, row, col], DataSeriesCollection)
134134
assert df[:, row, col].ntime == ntime
135135
assert df[:, row, col].shape == (ntime, 9)
136136

137-
assert isinstance(df[:, [1, 2, 3], [1, 2, 3]], DataFrame)
137+
assert isinstance(df[:, [1, 2, 3], [1, 2, 3]], DataSeriesCollection)
138138
assert df[:, [1, 2, 3], [1, 2, 3]].ntime == ntime
139139
assert df[:, [1, 2, 3], [1, 2, 3]].shape == (ntime, 3)
140140

141-
assert isinstance(df[:, 0, :], DataFrame)
141+
assert isinstance(df[:, 0, :], DataSeriesCollection)
142142
assert df[:, 0, :].ntime == ntime
143143
assert df[:, 0, :].shape == (ntime, ncol)
144144

145-
assert isinstance(df[:, :, 0], DataFrame)
145+
assert isinstance(df[:, :, 0], DataSeriesCollection)
146146
assert df[:, :, 0].ntime == ntime
147147
assert df[:, :, 0].shape == (ntime, nrow)
148148

149-
assert isinstance(df[:, :1, [1, 2]], DataFrame)
149+
assert isinstance(df[:, :1, [1, 2]], DataSeriesCollection)
150150
assert df[:, :1, [1, 2]].ntime == ntime
151151
assert df[:, :1, [1, 2]].shape == (ntime, 2)
152152

153-
assert isinstance(df[:, [0, 1], [1, 2]], DataFrame)
153+
assert isinstance(df[:, [0, 1], [1, 2]], DataSeriesCollection)
154154
assert df[:, [0, 1], [1, 2]].ntime == ntime
155155
assert df[:, [0, 1], [1, 2]].shape == (ntime, 2)
156156

@@ -359,7 +359,7 @@ def test_real_data():
359359
assert flux.downsample(5).array.shape == (8, 6, 6)
360360
assert flux.downsample(5).uncertainty.array.shape == (8, 6, 6)
361361

362-
assert isinstance(flux[:, aper], DataFrame)
362+
assert isinstance(flux[:, aper], DataSeriesCollection)
363363
assert isinstance(flux[:, aper].uncertainty, Uncertainty)
364364

365365
assert isinstance(flux[:, aper].sum(axis=1), DataSeries)
@@ -429,7 +429,7 @@ def test_bool_cube():
429429

430430
def test_bit_cube():
431431
"""Test BitwiseCube methods"""
432-
from lkdata import BitwiseCube, BitwiseFrame, BitwiseSeries
432+
from lkdata import BitwiseCube, BitwiseSeriesCollection, BitwiseSeries
433433

434434
def strip(string):
435435
return string.replace(" ", "").replace("\n", "")
@@ -480,7 +480,7 @@ def strip(string):
480480
).all()
481481

482482
# Frames
483-
assert isinstance(bitcube[:, [0, 1, 2, 3], :], BitwiseFrame)
483+
assert isinstance(bitcube[:, [0, 1, 2, 3], :], BitwiseSeriesCollection)
484484
bitframe = bitcube[:, [0, 1, 2, 3], :]
485485
assert bitframe.shape == (2, 16)
486486
# Ensure codes and values_display transferred to derivative product
@@ -499,7 +499,7 @@ def strip(string):
499499
"8:'C8',16:'C16'}{1:'C1',2:'C2',4:'C4',8:'C8',16:'C16'}"
500500
)
501501

502-
bitframe = BitwiseFrame(np.arange(0, 32).reshape(2, 16))
502+
bitframe = BitwiseSeriesCollection(np.arange(0, 32).reshape(2, 16))
503503
# New bitframe has no codes_dict, detailed display should be the same as bitset
504504
bitframe.values_display = "bitset"
505505
bitset_str = strip(bitframe.styler.to_string())

tests/test_dataset.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
DataSet,
99
)
1010
from lkdata.datacube import DataCube, BoolCube, BitwiseCube
11-
from lkdata.dataframe import DataFrame, BoolFrame, BitwiseFrame
11+
from lkdata.seriescollection import (
12+
DataSeriesCollection,
13+
BoolSeriesCollection,
14+
BitwiseSeriesCollection,
15+
)
1216
from lkdata.dataseries import DataSeries, BoolSeries, BitwiseSeries
1317

1418

@@ -60,7 +64,7 @@ def datacube(ntime, nrow, ncol):
6064
@pytest.fixture
6165
def dataframe(ntime, nrow, ncol):
6266
"""DataFrame"""
63-
return DataFrame(
67+
return DataSeriesCollection(
6468
np.random.rand(ntime, nrow * ncol), np.random.rand(ntime, nrow * ncol)
6569
)
6670

@@ -80,7 +84,7 @@ def boolcube(ntime, nrow, ncol):
8084
@pytest.fixture
8185
def boolframe(ntime, nrow, ncol):
8286
"""BoolFrame"""
83-
return BoolFrame(np.random.choice((True, False), (ntime, nrow * ncol)))
87+
return BoolSeriesCollection(np.random.choice((True, False), (ntime, nrow * ncol)))
8488

8589

8690
@pytest.fixture
@@ -98,7 +102,7 @@ def bitcube(ntime, nrow, ncol):
98102
@pytest.fixture
99103
def bitframe(ntime, nrow, ncol):
100104
"""BitwiseFrame"""
101-
return BitwiseFrame(np.random.choice(64, (ntime, nrow * ncol)))
105+
return BitwiseSeriesCollection(np.random.choice(64, (ntime, nrow * ncol)))
102106

103107

104108
@pytest.fixture
@@ -176,7 +180,7 @@ def test_dataset_init(data_only, sample_dataset, ntime):
176180
def test_dataset_getitem_string(data_only):
177181
"""Test keyword retreival"""
178182
assert isinstance(data_only["datacube"], DataCube)
179-
assert isinstance(data_only["dataframe"], DataFrame)
183+
assert isinstance(data_only["dataframe"], DataSeriesCollection)
180184
assert isinstance(data_only["dataseries"], DataSeries)
181185

182186

@@ -191,7 +195,7 @@ def test_dataset_getitem_tuple(data_only):
191195
"""Time and space slice"""
192196
subset = data_only[1:5, :]
193197
assert all(
194-
isinstance(val, (DataCube, DataFrame, DataSeries))
198+
isinstance(val, (DataCube, DataSeriesCollection, DataSeries))
195199
for val in subset.data_products.values()
196200
)
197201

@@ -213,7 +217,7 @@ def test_dataset_cubes_property(data_only):
213217
def test_dataset_frames_property(data_only):
214218
frames = data_only.frames
215219
assert "dataframe" in frames
216-
assert isinstance(frames["dataframe"], DataFrame)
220+
assert isinstance(frames["dataframe"], DataSeriesCollection)
217221

218222

219223
def test_dataset_series_property(data_only):

0 commit comments

Comments
 (0)