microdf-python 1.0.0__tar.gz → 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {microdf_python-1.0.0/microdf_python.egg-info → microdf_python-1.0.1}/PKG-INFO +1 -1
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf/microdataframe.py +7 -5
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf/tests/test_microseries_dataframe.py +9 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1/microdf_python.egg-info}/PKG-INFO +1 -1
- {microdf_python-1.0.0 → microdf_python-1.0.1}/pyproject.toml +1 -1
- {microdf_python-1.0.0 → microdf_python-1.0.1}/LICENSE +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/README.md +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf/__init__.py +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf/microseries.py +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf/tests/conftest.py +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf_python.egg-info/SOURCES.txt +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf_python.egg-info/dependency_links.txt +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf_python.egg-info/requires.txt +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/microdf_python.egg-info/top_level.txt +0 -0
- {microdf_python-1.0.0 → microdf_python-1.0.1}/setup.cfg +0 -0
|
@@ -218,13 +218,15 @@ class MicroDataFrame(pd.DataFrame):
|
|
|
218
218
|
def __getitem__(
|
|
219
219
|
self, key: Union[str, List]
|
|
220
220
|
) -> Union[pd.Series, pd.DataFrame]:
|
|
221
|
+
# Let pandas handle the initial slicing
|
|
221
222
|
result = super().__getitem__(key)
|
|
223
|
+
|
|
224
|
+
# If the result is a DataFrame, re-synchronize the weights
|
|
222
225
|
if isinstance(result, pd.DataFrame):
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return MicroDataFrame(result, weights=weights)
|
|
226
|
+
new_weights = self.weights.reindex(result.index)
|
|
227
|
+
return MicroDataFrame(result, weights=new_weights)
|
|
228
|
+
|
|
229
|
+
# Otherwise, the result is a Series or a scalar, so just return it
|
|
228
230
|
return result
|
|
229
231
|
|
|
230
232
|
def catch_series_relapse(self) -> None:
|
|
@@ -24,6 +24,15 @@ def test_df_init() -> None:
|
|
|
24
24
|
assert df.a.mean() == np.average(arr, weights=w)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
def test_handles_empty_index() -> None:
|
|
28
|
+
arr = np.array([0, 1, 1])
|
|
29
|
+
w = np.array([3, 0, 9])
|
|
30
|
+
df = mdf.MicroDataFrame({"a": arr}, weights=w)
|
|
31
|
+
|
|
32
|
+
empty_index = pd.Index([])
|
|
33
|
+
df[empty_index] # Implicit assert; checking for ValueError
|
|
34
|
+
|
|
35
|
+
|
|
27
36
|
def test_series_getitem() -> None:
|
|
28
37
|
arr = np.array([0, 1, 1])
|
|
29
38
|
w = np.array([3, 0, 9])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|