finbourne-sdk-utils 0.0.33__py3-none-any.whl → 0.0.35__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.
@@ -203,15 +203,50 @@ def create_property_definitions_from_file(
203
203
  # Make the column name LUSID friendly
204
204
  lusid_friendly_code = cocoon.utilities.make_code_lusid_friendly(column_name)
205
205
 
206
- # If there is no data Pandas infers a type of float, would prefer to infer object
206
+ # Check if column is all nulls
207
207
  if missing_property_data_frame[column_name].isnull().all():
208
208
  logging.warning(
209
- f"{column_name} is null, no type can be inferred it will be treated as a string"
209
+ f"{column_name} is entirely null, no type can be inferred - will be treated as a string"
210
210
  )
211
211
  data_type = "object"
212
212
  data_frame[column_name] = data_frame[column_name].astype(
213
213
  "object", copy=False
214
214
  )
215
+ else:
216
+ # Find the first non-null value to infer the proper type
217
+ first_valid_value = missing_property_data_frame[column_name].dropna().iloc[0]
218
+
219
+ # Infer the type from the first non-null value
220
+ inferred_type = type(first_valid_value).__name__
221
+
222
+ # Map Python types to pandas dtypes
223
+ type_mapping = {
224
+ 'str': 'object',
225
+ 'int': 'int64',
226
+ 'float': 'float64',
227
+ 'bool': 'bool',
228
+ 'Timestamp': 'datetime64[ns]',
229
+ }
230
+
231
+ # Get the appropriate pandas dtype
232
+ inferred_dtype = type_mapping.get(inferred_type, 'object')
233
+
234
+ # Only override if the current dtype is object and we found something more specific
235
+ if str(data_type) == 'object' and inferred_dtype != 'object':
236
+ logging.info(
237
+ f"{column_name} has leading nulls - inferring type '{inferred_dtype}' from first non-null value"
238
+ )
239
+ data_type = inferred_dtype
240
+ # Optionally convert the column to the inferred type
241
+ try:
242
+ data_frame[column_name] = data_frame[column_name].astype(
243
+ inferred_dtype, copy=False
244
+ )
245
+ except (ValueError, TypeError) as e:
246
+ logging.warning(
247
+ f"Could not convert {column_name} to {inferred_dtype}, keeping as object. Error: {e}"
248
+ )
249
+ data_type = 'object'
215
250
 
216
251
  # Create a request to define the property, assumes value_required is false for all
217
252
  property_request = lusid.models.CreatePropertyDefinitionRequest(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: finbourne-sdk-utils
3
- Version: 0.0.33
3
+ Version: 0.0.35
4
4
  Summary: Python utilities for LUSID V2 SDK
5
5
  Home-page: https://github.com/finbourne/finbourne-sdk-utils
6
6
  Author: FINBOURNE Technology
@@ -14,7 +14,7 @@ Requires-Dist: requests>=2.27.1
14
14
  Requires-Dist: coloredlogs>=14.0
15
15
  Requires-Dist: detect-delimiter>=0.1
16
16
  Requires-Dist: flatten-json>=0.1.7
17
- Requires-Dist: pandas>=1.1.4
17
+ Requires-Dist: pandas<=2.3.3,>=1.1.4
18
18
  Requires-Dist: PyYAML>=5.4
19
19
  Requires-Dist: tqdm>=4.52.0
20
20
  Requires-Dist: openpyxl>=3.0.7
@@ -7,7 +7,7 @@ finbourne_sdk_utils/cocoon/cocoon.py,sha256=eecSS8hkF6LyjZpoWhgZqnklrRkJBg4F9_3z
7
7
  finbourne_sdk_utils/cocoon/cocoon_printer.py,sha256=bDKHRBJV9s_ivPQ8WvNALwm0Z4lUidW34U--tfppCrY,14046
8
8
  finbourne_sdk_utils/cocoon/dateorcutlabel.py,sha256=02MSDQGiSFMycb0SAfHLwMORRiXcXhh39lmaL3TkgMc,5793
9
9
  finbourne_sdk_utils/cocoon/instruments.py,sha256=r92uUME_Er0pYiChg2hivW5qQ8oMzPB_E4bong1TeIw,17399
10
- finbourne_sdk_utils/cocoon/properties.py,sha256=wxGZDopWSg_hruCwADYRuWI9ZiXBvG3q-TAtIjH9aKY,14938
10
+ finbourne_sdk_utils/cocoon/properties.py,sha256=Ggl8C69A8DLpGeRQARMAD-IwnRUPog4TW3R0Is_gCHs,16511
11
11
  finbourne_sdk_utils/cocoon/seed_sample_data.py,sha256=SYvuq08j8BbzE3uQMoTmS-xrNtbJ2IRg6KJ1PBm-uVI,4390
12
12
  finbourne_sdk_utils/cocoon/systemConfiguration.py,sha256=qheX-jVTaKuD34DSJn57RyTu4jlLMyXjkSYGVe8goIM,3284
13
13
  finbourne_sdk_utils/cocoon/transaction_type_upload.py,sha256=xASAzh7ycOzksW--azya-QMtgci48w4phfhyxw7v-gg,4439
@@ -45,8 +45,8 @@ finbourne_sdk_utils/lpt/txn_config.py,sha256=4WIEzypXXuoHdbEDJLl90iZj7dYfV-KaE8d
45
45
  finbourne_sdk_utils/lpt/txn_config_yaml.py,sha256=F5kHG-7l5khJvnaLEndHurgmannCi-Pt3U6MMJRuJ9Y,17717
46
46
  finbourne_sdk_utils/pandas_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  finbourne_sdk_utils/pandas_utils/lusid_pandas.py,sha256=rJENs5lIYEKcwvYaagKc-ei_3sOnbNZT9oFLuO8PU6Y,4900
48
- finbourne_sdk_utils-0.0.33.dist-info/LICENSE,sha256=pT32QD9c76jv4OMjXhZrYpjqlZTuiex52qmKUsLKRQc,1066
49
- finbourne_sdk_utils-0.0.33.dist-info/METADATA,sha256=z1o4qEZd8G3F3zajULuZaXEy0IXmmrzJe0Of7qCPNZ4,731
50
- finbourne_sdk_utils-0.0.33.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
51
- finbourne_sdk_utils-0.0.33.dist-info/top_level.txt,sha256=DiS6bVuYtHoXKSgWOlYhiXKPVFCJqhdtmQgMCGNZxxY,29
52
- finbourne_sdk_utils-0.0.33.dist-info/RECORD,,
48
+ finbourne_sdk_utils-0.0.35.dist-info/LICENSE,sha256=pT32QD9c76jv4OMjXhZrYpjqlZTuiex52qmKUsLKRQc,1066
49
+ finbourne_sdk_utils-0.0.35.dist-info/METADATA,sha256=eU1GIrPS7Kgyzeb5RfSGwOvIsLYIO4RZlnBZJuylD7M,739
50
+ finbourne_sdk_utils-0.0.35.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
51
+ finbourne_sdk_utils-0.0.35.dist-info/top_level.txt,sha256=DiS6bVuYtHoXKSgWOlYhiXKPVFCJqhdtmQgMCGNZxxY,29
52
+ finbourne_sdk_utils-0.0.35.dist-info/RECORD,,