funcsim 0.2.0__tar.gz → 0.2.2__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.
Files changed (36) hide show
  1. {funcsim-0.2.0/funcsim.egg-info → funcsim-0.2.2}/PKG-INFO +1 -1
  2. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/__init__.py +1 -1
  3. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/kde.py +4 -1
  4. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/plotting.py +32 -42
  5. {funcsim-0.2.0 → funcsim-0.2.2/funcsim.egg-info}/PKG-INFO +1 -1
  6. {funcsim-0.2.0 → funcsim-0.2.2}/setup.py +1 -1
  7. {funcsim-0.2.0 → funcsim-0.2.2}/LICENSE +0 -0
  8. {funcsim-0.2.0 → funcsim-0.2.2}/MANIFEST.in +0 -0
  9. {funcsim-0.2.0 → funcsim-0.2.2}/README.md +0 -0
  10. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/addist.py +0 -0
  11. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/conversions.py +0 -0
  12. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/copfit.py +0 -0
  13. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/core.py +0 -0
  14. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/cpt.py +0 -0
  15. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/cvmdist.py +0 -0
  16. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/dependence.py +0 -0
  17. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/distfit.py +0 -0
  18. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/ecdfgof.py +0 -0
  19. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/edf.py +0 -0
  20. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/eut.py +0 -0
  21. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/imanconover.py +0 -0
  22. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/ksdist.py +0 -0
  23. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/multicore.py +0 -0
  24. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/nearby.py +0 -0
  25. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/rdarrays.py +0 -0
  26. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/screen.py +0 -0
  27. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/shapiro.py +0 -0
  28. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/shrinkage.py +0 -0
  29. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/testsim.py +0 -0
  30. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/utests.py +0 -0
  31. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim/vect.py +0 -0
  32. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/SOURCES.txt +0 -0
  33. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/dependency_links.txt +0 -0
  34. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/requires.txt +0 -0
  35. {funcsim-0.2.0 → funcsim-0.2.2}/funcsim.egg-info/top_level.txt +0 -0
  36. {funcsim-0.2.0 → funcsim-0.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funcsim
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: functional, simple stochastic simulation
5
5
  Home-page: https://github.com/h-bryant/funcsim
6
6
  Author: Henry Bryant
@@ -48,4 +48,4 @@ def version():
48
48
  str
49
49
  The version string of the package (e.g., '0.1.5').
50
50
  """
51
- return "0.2.0"
51
+ return "0.2.2"
@@ -75,7 +75,10 @@ class Kde():
75
75
  float
76
76
  The estimated probability density at v.
77
77
  """
78
- return float(self.gkde(v))
78
+ # gaussian_kde returns a length-1 array for a scalar input, and
79
+ # NumPy >= 2.5 raises TypeError on float() of any array that is
80
+ # not 0-dimensional, so index out the single element first
81
+ return float(self.gkde(v)[0])
79
82
 
80
83
  @vectorized_method
81
84
  def cdf(self,
@@ -8,6 +8,32 @@ from typing import Callable, Optional
8
8
  from . import conversions
9
9
 
10
10
 
11
+ def _xvalues(idx: pd.Index) -> list:
12
+ """
13
+ Convert a 'steps' index into a list of x values that any JSON encoder
14
+ can serialize.
15
+
16
+ pandas Period and Timestamp labels are rendered as ISO 8601 strings,
17
+ which plotly.js parses back into a date axis. Static image export via
18
+ kaleido >= 1.0 serializes the figure with orjson, which rejects pandas
19
+ Timestamp objects outright, so the conversion cannot be left to plotly.
20
+ Other label types (e.g. integers) pass through unchanged.
21
+ """
22
+ if isinstance(idx, pd.PeriodIndex):
23
+ idx = idx.to_timestamp()
24
+ if isinstance(idx, pd.DatetimeIndex):
25
+ return [ts.isoformat() for ts in idx]
26
+
27
+ def conv(item):
28
+ if isinstance(item, pd.Period):
29
+ return item.to_timestamp().isoformat()
30
+ if isinstance(item, pd.Timestamp):
31
+ return item.isoformat()
32
+ return item
33
+
34
+ return [conv(item) for item in idx]
35
+
36
+
11
37
  def fan(da: xr.DataArray,
12
38
  varname: str,
13
39
  filepath: str = None,
@@ -24,7 +50,7 @@ def fan(da: xr.DataArray,
24
50
  Simulation results with dimensions "trials", "variables", "steps".
25
51
  varname : str
26
52
  Name of the variable to plot from the "variables" dimension.
27
- filepath : str, opti
53
+ filepath : str, optional
28
54
  Path to save the chart. Supports HTML and image formats. Default None.
29
55
  line_color : str, optional
30
56
  Color of the mean line. Default is 'blue'.
@@ -75,45 +101,9 @@ def fan(da: xr.DataArray,
75
101
  fig.update_layout(title_text=f"{varname} (No data)")
76
102
  return fig
77
103
 
78
- # 'steps' values from the index of the transposed DataFrame
79
- idx_original = dt.index # Keep original for potential messages or fallback
80
- idx = dt.index
81
-
82
- # Ensure index is JSON serializable by converting to Timestamps if it
83
- # contains Periods. This handles both PeriodIndex and object-dtype Index
84
- # containing Period objects.
85
- if isinstance(idx, pd.PeriodIndex):
86
- idx = idx.to_timestamp()
87
- # print("DEBUG: Converted PeriodIndex to DatetimeIndex.") # Optional
88
- elif hasattr(idx, 'dtype') and pd.api.types.is_object_dtype(idx.dtype):
89
- # If it's an object-dtype idx, check if it might contain Period objects.
90
- if len(idx) > 0:
91
- try:
92
- converted_values = []
93
- needs_conversion = False
94
- for item in idx:
95
- if isinstance(item, pd.Period):
96
- converted_values.append(item.to_timestamp())
97
- needs_conversion = True
98
- else:
99
- # Pass through other types (e.g., pd.NaT, None, or
100
- # other data if mixed)
101
- converted_values.append(item)
102
-
103
- if needs_conversion:
104
- idx = pd.DatetimeIndex(converted_values)
105
- # print("DEBUG: Converted object-dtype index with Period "
106
- # "objects to DatetimeIndex.") # Optional debug
107
- # If no Period objects were found and converted, idx remains the
108
- # original object-dtype index.
109
-
110
- except Exception as e:
111
- # This might happen if conversion of an item fails unexpectedly.
112
- warnings.warn(f"Attempted to convert an object-dtype "
113
- f"index that might contain Periods, but an error "
114
- f"occurred: {e}. Using original index for x-axis,"
115
- f" which may lead to Plotly errors.", UserWarning)
116
- idx = idx_original # Revert to original index
104
+ # x values for the 'steps' axis, in a form every JSON encoder can
105
+ # serialize (see _xvalues)
106
+ xs = _xvalues(dt.index)
117
107
 
118
108
  # Calculate the mean across trials for each step
119
109
  mean_values = dt.mean(axis=1)
@@ -140,7 +130,7 @@ def fan(da: xr.DataArray,
140
130
  # start for the lower bound
141
131
  # Y-coordinates match this path to create a closed shape
142
132
  fig.add_trace(go.Scatter(
143
- x=list(idx) + list(idx[::-1]),
133
+ x=xs + xs[::-1],
144
134
  y=list(y_upper) + list(y_lower[::-1]),
145
135
  fill='toself', # Fill the area enclosed by the trace
146
136
  fillcolor='rgba(173, 216, 230, 0.4)', # Light blue with 20% opacity
@@ -152,7 +142,7 @@ def fan(da: xr.DataArray,
152
142
 
153
143
  # Add the mean line (plotted on top of the bands)
154
144
  fig.add_trace(go.Scatter(
155
- x=idx,
145
+ x=xs,
156
146
  y=mean_values,
157
147
  mode='lines',
158
148
  line=dict(color=line_color), # Use the specified line color
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funcsim
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: functional, simple stochastic simulation
5
5
  Home-page: https://github.com/h-bryant/funcsim
6
6
  Author: Henry Bryant
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="funcsim",
8
- version="0.2.0",
8
+ version="0.2.2",
9
9
  license="bsd-3-clause",
10
10
  author="Henry Bryant",
11
11
  author_email="henry@tamu.edu",
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
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes