rgwfuncs 0.0.94__py3-none-any.whl → 0.0.95__py3-none-any.whl

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.
rgwfuncs/df_lib.py CHANGED
@@ -2087,11 +2087,12 @@ def sync_dataframe_to_sqlite_database(
2087
2087
 
2088
2088
  def load_fresh_data_or_pull_from_cache(fetch_func: Callable[[], pd.DataFrame], cache_dir: str, file_prefix: str, cache_cutoff_hours: int, dtype: dict = None) -> pd.DataFrame:
2089
2089
  """
2090
- Retrieve data from a cache if a recent cache file exists, or fetch fresh data, save it to the cache, and return it.
2090
+ Retrieve data from a cache if a recent cache file exists, or fetch fresh data, save it to the cache, remove older cache files, and return it.
2091
2091
 
2092
2092
  This function checks a specified directory for the most recent cache file matching a specified prefix.
2093
2093
  If a recent cache file (within the cutoff time in hours) is found, the data is read from there.
2094
- Otherwise, it calls the data-fetching function, saves the newly fetched data to a new cache file, and returns it.
2094
+ Otherwise, it calls the data-fetching function, saves the newly fetched data to a new cache file,
2095
+ removes all earlier cache files with the same prefix, and returns the data.
2095
2096
 
2096
2097
  Parameters:
2097
2098
  - fetch_func (typing.Callable[[], pd.DataFrame]):
@@ -2145,4 +2146,12 @@ def load_fresh_data_or_pull_from_cache(fetch_func: Callable[[], pd.DataFrame], c
2145
2146
  cache_filename: str = f"{file_prefix}_{current_time_str}.csv"
2146
2147
  df.to_csv(os.path.join(cache_dir, cache_filename), index=False)
2147
2148
 
2149
+ # Remove all earlier cache files with the same prefix
2150
+ for filename in os.listdir(cache_dir):
2151
+ if filename.startswith(file_prefix) and filename.endswith(".csv") and filename != cache_filename:
2152
+ try:
2153
+ os.remove(os.path.join(cache_dir, filename))
2154
+ except OSError:
2155
+ continue
2156
+
2148
2157
  return df
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rgwfuncs
3
- Version: 0.0.94
3
+ Version: 0.0.95
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -1735,7 +1735,7 @@ Processes and saves a DataFrame to an SQLite database, adding a timestamp column
1735
1735
 
1736
1736
  ### 46. `load_fresh_data_or_pull_from_cache`
1737
1737
 
1738
- Retrieves data from a cache if a recent cache file exists, or fetches fresh data, saves it to the cache, and returns it. If the cache is too old or doesn’t exist, it uses a fetching function to get new data, which it caches and returns. An optional `dtype` parameter allows specifying column data types when reading from the cache, preventing issues with mixed-type columns.
1738
+ Retrieves data from a cache if a recent cache file exists, or fetches fresh data, saves it to the cache, removes older cache files, and returns it. If the cache is too old or doesn’t exist, it uses a fetching function to get new data, which it caches and returns. When fresh data is fetched and saved, all earlier cache files with the same prefix are deleted to keep the cache directory clean. An optional `dtype` parameter allows specifying column data types when reading from the cache, preventing issues with mixed-type columns.
1739
1739
 
1740
1740
  #### Parameters:
1741
1741
  - **`fetch_func` (typing.Callable[[], pd.DataFrame])**: A callable function that fetches fresh data and returns it as a pandas DataFrame.
@@ -1,12 +1,12 @@
1
1
  rgwfuncs/__init__.py,sha256=LSn54Tlyskcb6Wab_wUpPLB6UGMe5LdrB3GU88mDEbU,1712
2
2
  rgwfuncs/algebra_lib.py,sha256=rKFITfpWfgdBswnbMUuS41XgndEt-jUVz2ObO_ik7eM,42234
3
- rgwfuncs/df_lib.py,sha256=SUEjUc8kCELtbQE2luMsBGh18aTWS97Wb5s3RdMcmHc,75750
3
+ rgwfuncs/df_lib.py,sha256=BoBICtf_uy1AOuduGenJemtTTpF4alalSq0Nuyy88F4,76207
4
4
  rgwfuncs/docs_lib.py,sha256=i63NzX-V8cGhikYdtkRGAEe2VcuwpXxDUyTRa9xI7l8,1972
5
5
  rgwfuncs/interactive_shell_lib.py,sha256=YN0ZnM5twIsOeDKuOQ9ZGURCvvBX0RZjM4a1vO1C3E8,4281
6
6
  rgwfuncs/str_lib.py,sha256=hE0VfP6rhQpczsKyCZvH3G1aMRwngKnkW3NTYCEc0Po,3208
7
- rgwfuncs-0.0.94.dist-info/licenses/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
- rgwfuncs-0.0.94.dist-info/METADATA,sha256=K0ehKuNHmsn7IbtRWM8o7_323F8RUnYNtry2QHosFWo,62066
9
- rgwfuncs-0.0.94.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
10
- rgwfuncs-0.0.94.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
- rgwfuncs-0.0.94.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
- rgwfuncs-0.0.94.dist-info/RECORD,,
7
+ rgwfuncs-0.0.95.dist-info/licenses/LICENSE,sha256=jLvt20gcUZYB8UOvyBvyKQ1qhYYhD__qP7ZDx2lPFkU,1062
8
+ rgwfuncs-0.0.95.dist-info/METADATA,sha256=TPX6a5GjVlF_KIUytC2J_bi5nILxBSp9ArUoMuwRC8s,62223
9
+ rgwfuncs-0.0.95.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
10
+ rgwfuncs-0.0.95.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
11
+ rgwfuncs-0.0.95.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
12
+ rgwfuncs-0.0.95.dist-info/RECORD,,