@@ -35,17 +35,44 @@ def contig_neighbors(
3535 Primary Feature Layer Columns Referenced:
3636 opa_id, vacant
3737 """
38+ print (f"[DEBUG] contig_neighbors: Starting with { len (input_gdf )} properties" )
39+ print (f"[DEBUG] contig_neighbors: Vacant properties: { input_gdf ['vacant' ].sum ()} " )
40+
41+ # Debug geometry types
42+ geometry_types = input_gdf .geometry .type .value_counts ()
43+ print (
44+ f"[DEBUG] contig_neighbors: Geometry types in dataset: { dict (geometry_types )} "
45+ )
46+
47+ # Debug vacant properties geometry types
48+ vacant_gdf = input_gdf [input_gdf ["vacant" ]]
49+ if len (vacant_gdf ) > 0 :
50+ vacant_geometry_types = vacant_gdf .geometry .type .value_counts ()
51+ print (
52+ f"[DEBUG] contig_neighbors: Vacant properties geometry types: { dict (vacant_geometry_types )} "
53+ )
54+ else :
55+ print ("[DEBUG] contig_neighbors: No vacant properties found" )
56+
3857 # Create a filtered dataframe with only vacant properties and polygon geometries
3958 vacant_parcels = input_gdf .loc [
4059 (input_gdf ["vacant" ])
4160 & (input_gdf .geometry .type .isin (["Polygon" , "MultiPolygon" ])),
4261 ["opa_id" , "geometry" ],
4362 ]
4463
64+ print (
65+ f"[DEBUG] contig_neighbors: Vacant parcels with valid geometry: { len (vacant_parcels )} "
66+ )
67+
4568 if vacant_parcels .empty :
4669 print ("No vacant properties found in the dataset." )
4770 input_gdf ["n_contiguous" ] = np .nan
48- return input_gdf
71+ print ("[DEBUG] contig_neighbors: Returning single value (should be tuple)" )
72+ result = input_gdf , ValidationResult (True )
73+ print (f"[DEBUG] contig_neighbors: Return type: { type (result )} " )
74+ print (f"[DEBUG] contig_neighbors: Return length: { len (result )} " )
75+ return result
4976
5077 with warnings .catch_warnings ():
5178 warnings .filterwarnings ("ignore" , category = FutureWarning )
@@ -66,13 +93,110 @@ def contig_neighbors(
6693 node : len (nx .node_connected_component (g , node )) - 1 for node in g .nodes
6794 }
6895
96+ # Debug: Check what values we're getting
97+ print (
98+ f"[DEBUG] contig_neighbors: n_contiguous values calculated: { len (n_contiguous )} "
99+ )
100+ if len (n_contiguous ) > 0 :
101+ sample_values = list (n_contiguous .values ())[:10 ]
102+ print (f"[DEBUG] contig_neighbors: Sample n_contiguous values: { sample_values } " )
103+ print (
104+ f"[DEBUG] contig_neighbors: n_contiguous value types: { [type (v ) for v in sample_values ]} "
105+ )
106+
69107 # Assign the contiguous neighbor count to the filtered vacant parcels
70108 vacant_parcels ["n_contiguous" ] = vacant_parcels .index .map (n_contiguous )
71109
110+ # Debug: Check what's in vacant_parcels after assignment
111+ print (
112+ f"[DEBUG] contig_neighbors: vacant_parcels n_contiguous column: { vacant_parcels ['n_contiguous' ].dtype } "
113+ )
114+ print (
115+ f"[DEBUG] contig_neighbors: vacant_parcels n_contiguous sample: { vacant_parcels ['n_contiguous' ].head ().tolist ()} "
116+ )
117+ print (
118+ f"[DEBUG] contig_neighbors: vacant_parcels n_contiguous null count: { vacant_parcels ['n_contiguous' ].isna ().sum ()} "
119+ )
120+
121+ # Debug: Check for boolean values in vacant_parcels
122+ bool_mask = vacant_parcels ["n_contiguous" ].apply (lambda x : isinstance (x , bool ))
123+ if bool_mask .any ():
124+ print (
125+ f"[DEBUG] contig_neighbors: Found { bool_mask .sum ()} boolean values in vacant_parcels!"
126+ )
127+ print (
128+ f"[DEBUG] contig_neighbors: Boolean values: { vacant_parcels .loc [bool_mask , 'n_contiguous' ].tolist ()} "
129+ )
130+
131+ # Debug: Check opa_id matching
132+ print (
133+ f"[DEBUG] contig_neighbors: vacant_parcels opa_id sample: { vacant_parcels ['opa_id' ].head ().tolist ()} "
134+ )
135+ print (
136+ f"[DEBUG] contig_neighbors: input_gdf opa_id sample: { input_gdf ['opa_id' ].head ().tolist ()} "
137+ )
138+ print (
139+ f"[DEBUG] contig_neighbors: vacant_parcels opa_id type: { vacant_parcels ['opa_id' ].dtype } "
140+ )
141+ print (
142+ f"[DEBUG] contig_neighbors: input_gdf opa_id type: { input_gdf ['opa_id' ].dtype } "
143+ )
144+
72145 # Merge the results back to the primary feature layer
73146 input_gdf = opa_join (input_gdf , vacant_parcels [["opa_id" , "n_contiguous" ]])
74147
148+ # Debug: Check what's in input_gdf after join
149+ print (
150+ f"[DEBUG] contig_neighbors: input_gdf n_contiguous column: { input_gdf ['n_contiguous' ].dtype } "
151+ )
152+ print (
153+ f"[DEBUG] contig_neighbors: input_gdf n_contiguous sample: { input_gdf ['n_contiguous' ].head ().tolist ()} "
154+ )
155+ print (
156+ f"[DEBUG] contig_neighbors: input_gdf n_contiguous null count: { input_gdf ['n_contiguous' ].isna ().sum ()} "
157+ )
158+
159+ # Debug: Check for boolean values in input_gdf
160+ bool_mask = input_gdf ["n_contiguous" ].apply (lambda x : isinstance (x , bool ))
161+ if bool_mask .any ():
162+ print (
163+ f"[DEBUG] contig_neighbors: Found { bool_mask .sum ()} boolean values in input_gdf!"
164+ )
165+ print (
166+ f"[DEBUG] contig_neighbors: Boolean values: { input_gdf .loc [bool_mask , 'n_contiguous' ].tolist ()} "
167+ )
168+
169+ # Debug: Check if any non-null values exist
170+ non_null_mask = input_gdf ["n_contiguous" ].notna ()
171+ if non_null_mask .any ():
172+ print (
173+ f"[DEBUG] contig_neighbors: Found { non_null_mask .sum ()} non-null n_contiguous values"
174+ )
175+ print (
176+ f"[DEBUG] contig_neighbors: Non-null sample: { input_gdf .loc [non_null_mask , 'n_contiguous' ].head ().tolist ()} "
177+ )
178+ else :
179+ print (
180+ "[DEBUG] contig_neighbors: No non-null n_contiguous values found after join"
181+ )
182+
75183 # Assign NA for non-vacant properties
76184 input_gdf .loc [~ input_gdf ["vacant" ], "n_contiguous" ] = np .nan
77185
78- return input_gdf , ValidationResult (True )
186+ # Final check: Ensure no boolean values remain
187+ final_bool_mask = input_gdf ["n_contiguous" ].apply (lambda x : isinstance (x , bool ))
188+ if final_bool_mask .any ():
189+ print (
190+ f"[DEBUG] contig_neighbors: WARNING - Found { final_bool_mask .sum ()} boolean values in final result!"
191+ )
192+ print ("[DEBUG] contig_neighbors: Converting boolean values to numeric..." )
193+ # Convert boolean False to 0, True to 1
194+ input_gdf .loc [final_bool_mask , "n_contiguous" ] = input_gdf .loc [
195+ final_bool_mask , "n_contiguous"
196+ ].astype (int )
197+
198+ print ("[DEBUG] contig_neighbors: Returning tuple with ValidationResult" )
199+ result = input_gdf , ValidationResult (True )
200+ print (f"[DEBUG] contig_neighbors: Return type: { type (result )} " )
201+ print (f"[DEBUG] contig_neighbors: Return length: { len (result )} " )
202+ return result
0 commit comments