pycoustic 0.1.13__tar.gz → 0.1.14__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.3
2
2
  Name: pycoustic
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary:
5
5
  Author: thumpercastle
6
6
  Author-email: tony.ryb@gmail.com
@@ -35,10 +35,31 @@ class Survey:
35
35
  return df.set_index(idx, inplace=False)
36
36
 
37
37
  def _insert_header(self, df=None, new_head_list=None, header_idx=None):
38
- cols = df.columns.to_list()
39
- new_cols = [list(c) for c in zip(*cols)]
40
- new_cols.insert(header_idx, new_head_list)
41
- df.columns = new_cols
38
+ if df is None or new_head_list is None:
39
+ return df
40
+
41
+ ncols = df.shape[1]
42
+
43
+ # Allow scalar broadcast for convenience
44
+ if isinstance(new_head_list, (str, int, float)):
45
+ new_head_list = [new_head_list] * ncols
46
+
47
+ if len(new_head_list) != ncols:
48
+ raise ValueError(
49
+ f"new_head_list length ({len(new_head_list)}) must equal number of columns ({ncols})."
50
+ )
51
+
52
+ cols = list(df.columns)
53
+ # Normalize columns into list of tuples
54
+ if isinstance(df.columns, pd.MultiIndex):
55
+ tuples = cols # already list of tuples
56
+ else:
57
+ tuples = [(c,) for c in cols]
58
+
59
+ # Build arrays per level and insert new header list
60
+ arrays = [list(x) for x in zip(*tuples)]
61
+ arrays.insert(header_idx, list(new_head_list))
62
+ df.columns = pd.MultiIndex.from_arrays(arrays)
42
63
  return df
43
64
 
44
65
  # def _leq_by_date(self, data, cols=None):
@@ -113,34 +134,33 @@ class Survey:
113
134
  :return: A dataframe presenting a summary of the Leq and Lmax values requested.
114
135
  """
115
136
  combi = pd.DataFrame()
116
- period_headers = []
117
137
  if leq_cols is None:
118
138
  leq_cols = [("Leq", "A")]
119
139
  if max_cols is None:
120
140
  max_cols = [("Lmax", "A")]
121
141
 
122
- for key, lg in self._logs.items(): # changed: iterate items() to get lg directly
123
- combined_list = []
124
- headers_for_log = [] # new: collect headers per log
142
+ for key, lg in self._logs.items():
143
+ period_blocks = []
144
+ period_names = []
125
145
 
126
146
  # Day
127
147
  days = lg.leq_by_date(lg.get_period(data=lg.get_antilogs(), period="days"), cols=leq_cols)
128
148
  days.sort_index(inplace=True)
129
- combined_list.append(days)
130
- headers_for_log.extend(["Daytime"] * len(leq_cols)) # changed: don't reset global headers
149
+ period_blocks.append(days)
150
+ period_names.append("Daytime")
131
151
 
132
- # Evening
152
+ # Evening (optional)
133
153
  if lg.is_evening():
134
154
  evenings = lg.leq_by_date(lg.get_period(data=lg.get_antilogs(), period="evenings"), cols=leq_cols)
135
155
  evenings.sort_index(inplace=True)
136
- combined_list.append(evenings)
137
- headers_for_log.extend(["Evening"] * len(leq_cols))
156
+ period_blocks.append(evenings)
157
+ period_names.append("Evening")
138
158
 
139
159
  # Night Leq
140
160
  nights = lg.leq_by_date(lg.get_period(data=lg.get_antilogs(), period="nights"), cols=leq_cols)
141
161
  nights.sort_index(inplace=True)
142
- combined_list.append(nights)
143
- headers_for_log.extend(["Night-time"] * len(leq_cols))
162
+ period_blocks.append(nights)
163
+ period_names.append("Night-time")
144
164
 
145
165
  # Night max
146
166
  maxes = lg.as_interval(t=lmax_t)
@@ -153,17 +173,19 @@ class Survey:
153
173
  except Exception as e:
154
174
  print(f"Error converting index to date: {e}")
155
175
  maxes.index.name = None
156
- combined_list.append(maxes)
157
- headers_for_log.extend(["Night-time"] * len(max_cols))
176
+ period_blocks.append(maxes)
177
+ period_names.append("Night-time")
158
178
 
159
- summary = pd.concat(objs=combined_list, axis=1)
179
+ # Build Period as a proper column level to avoid manual header length mismatches
180
+ summary = pd.concat(objs=period_blocks, axis=1, keys=period_names, names=["Period"])
181
+
182
+ # Add the per-log super level (kept as before)
160
183
  summary = self._insert_multiindex(df=summary, super=key)
161
- combi = pd.concat(objs=[combi, summary], axis=0)
162
184
 
163
- # append this log's headers to the global list
164
- period_headers.extend(headers_for_log)
185
+ # Stack logs by rows; columns remain aligned across logs
186
+ combi = pd.concat(objs=[combi, summary], axis=0)
165
187
 
166
- combi = self._insert_header(df=combi, new_head_list=period_headers, header_idx=0)
188
+ # No manual header insertion needed anymore; Period is already a column level
167
189
  return combi
168
190
  #test
169
191
  def modal(self, cols=None, by_date=False, day_t="60min", evening_t="60min", night_t="15min"):
@@ -493,43 +515,4 @@ class WeatherHistory:
493
515
  # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pycoustic\survey.py", line 328, in weather_summary
494
516
  # return pd.DataFrame([self._weatherhist.min(), self._weatherhist.max(), self._weatherhist.mean()],
495
517
  # ^^^^^^^^^^^^^^^^^^^^^^^
496
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\frame.py", line 11643, in min
497
- # result = super().min(axis, skipna, numeric_only, **kwargs)
498
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
499
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\generic.py", line 12388, in min
500
- # return self._stat_function(
501
- # ^^^^^^^^^^^^^^^^^^^^
502
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\generic.py", line 12377, in _stat_function
503
- # return self._reduce(
504
- # ^^^^^^^^^^^^^
505
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\frame.py", line 11562, in _reduce
506
- # res = df._mgr.reduce(blk_func)
507
- # ^^^^^^^^^^^^^^^^^^^^^^^^
508
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\internals\managers.py", line 1500, in reduce
509
- # nbs = blk.reduce(func)
510
- # ^^^^^^^^^^^^^^^^
511
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\internals\blocks.py", line 404, in reduce
512
- # result = func(self.values)
513
- # ^^^^^^^^^^^^^^^^^
514
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\frame.py", line 11481, in blk_func
515
- # return op(values, axis=axis, skipna=skipna, **kwds)
516
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
517
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\nanops.py", line 147, in f
518
- # result = alt(values, axis=axis, skipna=skipna, **kwds)
519
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
520
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\nanops.py", line 404, in new_func
521
- # result = func(values, axis=axis, skipna=skipna, mask=mask, **kwargs)
522
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
523
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\pandas\core\nanops.py", line 1098, in reduction
524
- # result = getattr(values, meth)(axis)
525
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^
526
- # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\numpy\_core\_methods.py", line 48, in _amin
527
- # return umr_minimum(a, axis, None, out, keepdims, initial, where)
528
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
529
- # TypeError: '<=' not supported between instances of 'dict' and 'dict'
530
-
531
-
532
- #TODO: Fix this error:
533
- #
534
- # C:\Users\tonyr\PycharmProjects\pycoustic\pycoustic\survey.py:316: FutureWarning:
535
- # The behavior of pd.concat with len(keys) != len(objs) is deprecated. In a future version this will raise instead of truncating to the smaller of the two sequences
518
+ # File "C:\Users\tonyr\PycharmProjects\pycoustic\.venv2\Lib\site-packages\
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pycoustic"
3
- version = "0.1.13"
3
+ version = "0.1.14"
4
4
  description = ""
5
5
  authors = ["thumpercastle <tony.ryb@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes