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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: microdf-python
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Weighted pandas DataFrames and Series for survey microdata
5
5
  Author-email: Max Ghenis <max@ubicenter.org>
6
6
  License: MIT
@@ -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
- try:
224
- weights = self.weights[key]
225
- except Exception:
226
- weights = self.weights
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])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: microdf-python
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Weighted pandas DataFrames and Series for survey microdata
5
5
  Author-email: Max Ghenis <max@ubicenter.org>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "microdf-python"
7
- version = "1.0.0"
7
+ version = "1.0.1"
8
8
  description = "Weighted pandas DataFrames and Series for survey microdata"
9
9
  readme = "README.md"
10
10
  authors = [
File without changes
File without changes
File without changes